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

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Determining which ListTemplates item is in use (VBA Word 2000)

    Author
    Topic
    #374840

    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).ListTemplates.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

    Viewing 1 reply thread
    Author
    Replies
    • #607808

      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.

    • #607820

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

      • #607836

        Been there, tried that, all to no avail.

        Thanks for trying.
        Troy

        • #607855

          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.

        • #608582

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

          • #608662

            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

            • #609107

              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.

              cheersKlaus

            • #609117

              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 bow , and let me know if you have any thoughts!!
              Troy

            • #609186

              Give the List Template that’s used for your heading styles a name:

                ActiveDocument.Styles(wdStyleHeading1).ListTemplate.Name = "myHeadings"

              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:

                ActiveDocument.ListTemplates("myHeadings").ListLevels(1).StartAt = 13

              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.

              cheersKlaus

            • #609264

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

            • #609320

              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 grin

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

              cheersKlaus

            • #610120

              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

            • #610508

              Basically, you would create a named list template, and use that instead of the ListGallery list template (that is, replace ListGalleries(wdOutlineNumberGallery).ListTemplates(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.

              cheersKlaus

            • #624629

              (Edited by TroyWells on 16-Oct-02 15:25. )

              Klaus or anyone,
              I have used the following line of code successfully again and again:

              ActiveDocument.Styles(wdStyleHeading1).ListTemplate.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

    Viewing 1 reply thread
    Reply To: Determining which ListTemplates item is in use (VBA Word 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: