Create a simple list in VBA

D

dunston

I am creating a word document from an ASP page and want to create a simple list.

Here is what I am looking at:
....
Set MyList = WordDoc.ListTemplates.Add()

'Add list items here
do while not orstemp.eof
'don't know what to do here
MyList.AddItem orstemp("name") & ", " & orstemp("division")
orstemp.movenext
loop
....

Thanks.
 
S

Shauna Kelly

Hi Dunston

The basic steps would be:
1. Setup
a. Set up an appropriate style for your numbered text.
b. Create a listtemplate (eg set oMyNewListTemplate = ActiveDocument.ListTemplates.Add)
c. Link the appropriate style to each level in the list template. This is the crucial issue. You want something like
oMyNewListTemplate.ListLevels(1).LinkedStyle = ActiveDocument.Styles(wdStyleListNumber)

2. Text
a. Add the text to the document.
b. Apply the appropriate style to the text

How to do this in the user interface is at http://www.ShaunaKelly.com/word/numbering/OutlineNumbering.html. It may be worth working
through it in the UI before coding it. That page talks about headings, but the principle applies to any numbering scheme.

Information about coding is at http://www.mvps.org/word/FAQs/Numbering/CureListNumbering.htm

Two hints:
1. If you record any macros to get the feel of the process, Word will record using the ListGalleries. Don't use these for the
reasons explained at http://www.mvps.org/word/FAQs/Numbering/WordsNumberingExplained.htm

2. If you're writing for a broad audience, use Word's built-in styles and refer to them using Word's constants (like
wdStyleListNumber). You can be sure those styles will exist in any document, and the constants solve problems of running the code on
a non-English version of Word.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
Melbourne, Australia
 

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