Create a bullet list automatically

N

Neale

Hi all,

I am trying to output records from a database into a particular part of a
word document. That bit works fine, and I have created a document template
with a bookmark to receive the data.

The problem I have is that the items are not appearing as a bulleted list as
I expect. I have trawled the word object model and tried various methods
without success :eek:(

Here is some of the code I have written (missing the variable declarations),
with the database records being replaced with a for...next loop to create
some lines of data temporarily to test the concept;

Set wdApp = New Word.Application
wdApp.Documents.Open strDocPath & strDocName

Set wdBookmarks = wdApp.ActiveDocument.bookmarks
Set wdLstTemplate = wdApp.ListGalleries(wdBulletGallery).ListTemplates(1)

' Update the document bookmark range with the new text
On Error GoTo Error_DocumentNotValidForExport
Set wdRange = wdApp.ActiveDocument.bookmarks("Requirements").Range
For l% = 1 To sngNumLines
strNewText = strNewText & vbTab & "Auto Line " & l% & " inserted" &
vbCrLf
Next l%

// THIS IS ONE METHOD ATTEMPTED TO APPLY A BULLET FORMAT TO THE LIST
If wdRange.ListFormat.ListType = wdListNoNumbering Then
wdRange.ListFormat.ApplyBulletDefault
End If
// END METHOD

// THIS IS ANOTHER METHOD I TRIED
wdRange.ListFormat.ApplyListTemplate ListTemplate:=wdLstTemplate, _
ContinuePreviousList:=False, ApplyTo:=wdListApplyToWholeList, _
DefaultListBehavior:=wdWord8ListBehavior
// END METHOD

// THE REMAINDER OF THE CODE I AM HAPPY WITH
wdRange.Text = strNewText
wdBookmarks.Add "Requirements", wdRange
On Error GoTo 0

wdApp.ActiveDocument.Save
wdApp.Quit
Set wdBookmarks = Nothing
Set wdLstTemplate = Nothing
Set wdApp = Nothing
 
N

Neale

A bit more information - sorry;

I am running the code from within an access 2003 database.
I am using word 2000
 
N

Neale

Thanks Shauna,

This works just fine, but only providing the style is applied to an existing
block of text in a range, whereas some of the other methods I was reviewing
apply the style to a range object and then add the text to the styled range,
which requires that the style be turned off as well.

If I apply a style using this method to an empty range and then add text to
the range, it does not apply the style, however my original plan was to build
the list and then apply the style so it's perfect for me, thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top