Using VBA code in Access, I send a report to an RTF file and then I
open the RTF file in Word. I then need to format the RTF file so that
it looks professional and polished.
I have written a macro (below) which I use to turn an ordinary list
into one with bullet points. The lines I need to make into bullet
points start with "^pXBULLX". The macro works fine on my machine but
when it is run on another machine, the bullet character changes from a
"-" to what looks like a letterbox symbol.
Apologies to be asking something that I think others have asked
before, but I've spent most of the day going through these newsgroups
and I'm confused. I've read that a ListTemplate shouldn't be applied
directly to text (and this is what I think I'm doing). I've also read
that ListGalleries shouldn't be used because they differ from machine
to machine.
Can someone please help me and offer me a nice and simple solution? :)
Thanks!
Pawel
This is my macro:
Sub Bullets(wrdApp As Word.Application, wrdDoc As Word.Document)
'
' Turn paragraphs starting with "<hard return>XBULLX" into bulleted
paragraphs.
'
Dim myList As ListTemplate
Set myList = wrdApp.ListGalleries(wdBulletGallery).ListTemplates(6)
' Define the properties for the bullet points:
'
With myList.ListLevels(1)
.NumberFormat = "-"
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleBullet
.NumberPosition = wrdApp.CentimetersToPoints(0)
.Alignment = wdListLevelAlignLeft
.TextPosition = wrdApp.CentimetersToPoints(0.4)
.TabPosition = wrdApp.CentimetersToPoints(0.4)
.ResetOnHigher = 0
.StartAt = 1
.LinkedStyle = ""
End With
myList.Name = ""
' Apply the bullet points to lines that start with "^pXBULLX":
'
With wrdDoc.Content.Find
.ClearFormatting
.Text = "^pXBULLX"
Do While .Execute(Forward:=True, MatchWildcards:=False,
Wrap:=wdFindStop) = True
With .Parent.Paragraphs(2)
.TabStops.ClearAll
.Range.ListFormat.ApplyListTemplate
ListTemplate:=myList, ContinuePreviousList:=False,
ApplyTo:=wdListApplyToSelection
End With
Loop
End With
End Sub
Sub ABull()
Application.ScreenUpdating = False
Selection.HomeKey wdStory
With Selection.Find
.ClearFormatting
Do While .Execute("XBULLX")
With Selection
.HomeKey Unit:=wdLine
.MoveDown Unit:=wdParagraph, Count:=1,
Extend:=wdExtend
.Style = ActiveDocument.Styles("List Bullet")
.Collapse wdCollapseEnd
End With
Loop
End With
End Sub
Your message was a bit confusing because the "^p" part of your search
is unnecessary; the paragraph mark before the "XBULLX" doesn't count.
What I did was start some paragraphs with "XBULLX", others without,
and run this code. It adds a bullet plus indentation to the
paragraphs starting with "XBULLX" and leaves the others alone. Hope
that's what you need. - Bruce
pcl_...@yahoo.co.uk (Pawel Bylanski) wrote in message news:<5b359fb.03010...@posting.google.com>...
Sub ABull()
Application.ScreenUpdating = False
Selection.HomeKey wdStory
With Selection.Find
.ClearFormatting
Do While .Execute("^pXBULLX")
With Selection
.Collapse wdCollapseStart
.MoveRight wdCharacter
.MoveDown Unit:=wdParagraph, Count:=1,
Extend:=wdExtend
.Style = ActiveDocument.Styles("List Bullet")
.Collapse wdCollapseEnd
.MoveLeft wdCharacter
End With
Loop
End With
End Sub
To guarantee the consistent appearance of the List Bullet on all
machines, you might edit the style at the start of VBA code. - Bruce
pcl_...@yahoo.co.uk (Pawel Bylanski) wrote in message news:<5b359fb.03010...@posting.google.com>...
Dim myList As ListTemplate
Set myList = wrdDoc.ListTemplates.Add
i.e. instead of using some existing list template, I create my own,
and I no longer use ListGalleries. The rest of the macro is the same
as it was. I've tried this on two machines which previously showed
the letterbox bullets and they work. Can anyone see any major flaws
in my revised macro?
Thanks for the "List Bullet" style idea. I hadn't realised I could do
it this way. I'm no expert in this area...is it safe to assume that
the "List Bullet" style will always be present on every machine? Or
would it be better to create and define a new style in VBA, e.g. "My
Bullet" and then apply that?
Does anyone know of a good book which would make this Word VBA
programming less frustrating? Something that would say "if you want
to apply bullets, use styles rather than ListTemplates" and would
explain how to use ListTemplates/ListGalleries properly avoiding the
bugs etc. A lot of my code is through trial and error with the macro
recorder or through newsgroups or snippets of information here and
there.
Thanks,
Pawel
Empyrea...@aol.com (Bruce Brown) wrote in message news:<1d2f086c.03010...@posting.google.com>...
>Can anyone see any major flaws
> in my revised macro?
One problem with constantly adding new ListTemplates to the document is that there is a limit (I can't remember what it is, and it's
not included in the Word help file<*groan*>). However, if you're simply formatting the file for use once or twice, and then
discarding it, that won't be a problem.
> Thanks for the "List Bullet" style idea.
All formatting in Word should be applied using styles (well, that's a big, broad statement, and there are exceptions, but for this
purpose that rule will suffice). So Bruce's solution is the one I'd also recommend.
>is it safe to assume that
> the "List Bullet" style will always be present on every machine? Or
> would it be better to create and define a new style in VBA, e.g. "My
> Bullet" and then apply that?
"List Bullet" is a built-in style in every version of Word going back further than I can remember. You may safely assume it exists
on every machine.
> Does anyone know of a good book which would make this Word VBA
> programming less frustrating?
Everything I learned about numbering in Word I got from
http://www.mvps.org/word/FAQs/Numbering/CureListNumbering.htm
I think it's fair to say that the main messages there are:
1. Don't ever refer to the ListGalleries.
2. Use the construction ActiveDocument.ListTemplates("MyListTemplateName").ListLevels(1).LinkedStyle = "my style name"
Hope this helps.
Shauna
http://www.shaunakelly.com/word
"Pawel Bylanski" <pcl_...@yahoo.co.uk> wrote in message news:5b359fb.03011...@posting.google.com...
Thank you both very much for your help!
Pawel
http://www.mvps.org/word/FAQs/index.html
Go to the above MVP index and click the Macros/VBA tab. There's a
whole stocking full of goodies for people who are new to VBA for Word.
Info about books too. In my humble, if you can get your hands on
anything by Guy Hart-Davis about VBA for Word you're doing great.
Judging by the expertise your macro demonstrated it probably won't be
long before you're purveying solutions too. - Bruce
pcl_...@yahoo.co.uk (Pawel Bylanski) wrote in message news:<5b359fb.03011...@posting.google.com>...