Results 1 to 15 of 15
  1. #1
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Determining which ListTemplates item is in use (VBA Word 2000)

    Is there a way to determine the ListTemplates item in use in the selected paragraph? It seems I can find all kind of other information about a paragraph, but not which item in the gallery is being used (as an integer).

    This is what I have tried:

    ListGalleryNum = ListGalleries(wdOutlineNumberGallery).ListTemplate s.Item

    but that of course returns an arguement not optional error. It seems you can use this to specify the ListTemplates item, just not to determine it.

    Thanks for the help!!
    Troy

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Determining which ListTemplates item is in use (VBA Word 2000)

    Troy, I don't have time to look for this today or tomorrow, but you need something that is a property of the paragraph object. Also, .Item is a method of returning an item from a collection, and not a property.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Determining which ListTemplates item is in use (VBA Word 2000)

    Try using Selection.Range.ListFormat and Selection.Range.ListFormat.ListTemplate etc.

  4. #4
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determining which ListTemplates item is in use (VBA Word 2000)

    Been there, tried that, all to no avail.

    Thanks for trying.
    Troy

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Determining which ListTemplates item is in use (VBA Word 2000)

    I'm sorry, I can't find anything to do what you want. I don't know if it's possible, except maybe by tediously comparing all properties of the ListTemplate of the selected paragraph to the properties of the ListTemplates in the ListGallery. I hope that one of the Word/VBA gurus will be able to help you.

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Determining which ListTemplates item is in use (VBA Word 2000)

    I don't see any way to do it. Can we convince you that you don't need it?

  7. #7
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determining which ListTemplates item is in use (VBA Word 2000)

    Do I have to have it? No. It just makes things a little more foolproof. See I've got code that resets the starting number of the selected Heading 1. This code requires the ListTemplates item. This ListTemplates item is originally set when the style is applied/restored with another procedure. As long as I keep the same ListTemplate item in both procedures, I'll be fine. I just didn't want to have to count on me to remember.

    Thanks for looking!!
    Troy

  8. #8
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determining which ListTemplates item is in use (VBA Word 2000)

    You probably won't get any control unless you name your list template(s).

    But since you say you need to reset the starting number of the selected Heading 1, I'm curious why you would use a different list template anyway.
    If you change the starting number by applying a different list template, you'll probably end up with two lists, with different list templates. When you then copy stuff between the two different lists, the numbers won't adapt automatically.

    Perhaps if you describe in more detail what you want to achieve (that is, why you need a restart), there may be a better solution.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Klaus

  9. #9
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determining which ListTemplates item is in use (VBA Word 2000)

    Klaus,

    You just described exactly why want to determine the ListTemplate item. I want to avoid applying the wrong ListTemplates item by mistake by simply reseting the StartAt value. Often I work with large documents where each chapter is a separate file. If I need to reset the chapter number, which happens to reside in the Heading 1 paragraph, then I need to know the ListTemplates item in use because the code to reset the starting value requires this.

    With ListGalleries(wdOutlineNumberGallery).ListTemplates(5).ListLevels(1)
    .StartAt = ChapterNumber
    End With
    (Where ChapterNumber is a number or letter starting in an input box.)

    The code I have works great, but the ListTemplates(item) has to be hard coded. I am just concerned that at some point I will set the wrong ListTemplates item. That's why I want to determine what ListTemplates item is currently in use. Then I could put it in the code as a variable something like:

    With ListGalleries(wdOutlineNumberGallery).ListTemplates(ItemNumber).ListLevels(1)
    .StartAt = ChapterNumber
    End With

    Thanks for making the case for me <img src=/S/bow.gif border=0 alt=bow width=15 height=15> , and let me know if you have any thoughts!!
    Troy

  10. #10
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determining which ListTemplates item is in use (VBA Word 2000)

    Give the List Template that's used for your heading styles a name:
    <pre> ActiveDocument.Styles(wdStyleHeading1).ListTemplat e.Name = "myHeadings"</pre>


    Run that once, and the List Template that your Heading styles are linked to is called "myHeadings".

    From then on you can refer to it by name at any time:
    <pre> ActiveDocument.ListTemplates("myHeadings").ListLev els(1).StartAt = 13</pre>


    I was afraid you wanted to use two different list templates for headings in the same document, which would lead to chaos.
    As long as you only have one list template, that's fine.

    I wouldn't ever use the ListGalleries. You can get by without them easily.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Klaus

  11. #11
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determining which ListTemplates item is in use (VBA Word 2000)

    Thanks!! I learned something new. That did the trick!!
    Troy

  12. #12
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determining which ListTemplates item is in use (VBA Word 2000)

    If you define your list template from the user interface, you can type in the name of the list template directly (at the bottom left of the expanded dialog).

    Some numbering experts say that naming your list templates makes the numbering more robust, though I'm not sure about that... can't do harm, anyway <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    One nice thing is that as soon as you name your list template, the list template will be available for ListNum fields.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Klaus

  13. #13
    Star Lounger
    Join Date
    Jun 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determining which ListTemplates item is in use (VBA Word 2000)

    Greetings Klaus

    I have virtually the same problem with numbered Headings styles 'drifting'. Unfortunately the renumbering(in my case)
    was an adaption of the code generated by Words Macro recorder and does use ListGalleries.

    Could you point me in a direction that doesn't use ListGalleries?

    Frank

  14. #14
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determining which ListTemplates item is in use (VBA Word 2000)

    Basically, you would create a named list template, and use that instead of the ListGallery list template (that is, replace ListGalleries(wdOutlineNumberGallery).ListTemplate s(x) with oLT, where oLT is the named list template).

    This post from Dave Rado has more code; this post contains a complete example for setting up numbered heading styles with VBA.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Klaus

  15. #15
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determining which ListTemplates item is in use (VBA Word 2000)

    <P ID="edit" class=small>(Edited by TroyWells on 16-Oct-02 15:25. )</P>Klaus or anyone,
    I have used the following line of code successfully again and again:

    ActiveDocument.Styles(wdStyleHeading1).ListTemplat e.Name = "myHeadings"

    However, I got a document yesterday and ran my macro on it that contained this line of code. When it got to this line, I got an error that said:

    Run time error '91':

    Object variable or With block variable not set


    Because I don't get this problems with any other document, I'm guess there could be some doc corruption, but is there any other reason I would be getting this error? I'd like to make sure this code works with all documents if possible.

    EDIT: Actually I seem to get this on any new document not based on the documents I tested. I wonder now if I created this "myHeadings" list template in the base documents, which is why it works there, but it needs to be somehow set in the other documents. How do I do that?

    Thanks!!
    Troy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •