• Resetting a number in the middle of a list (Word 2003 VBA)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Resetting a number in the middle of a list (Word 2003 VBA)

    Author
    Topic
    #435097

    You should declare ListLev as ListLevel instead of as Long.

    Viewing 1 reply thread
    Author
    Replies
    • #1027458

      Sorry!! I did not name that variable well at all.

      The ListLev variable is actually the list. I will edit my original post and rename to “List1”. I was trying to follow an example I found in the online help by setting this.

      Sorry for the confusion, and please help!!

      Thanks!!
      Troy

      • #1027469

        Same problem. ListLevels(…) returns a ListLevel object, not a number. If you want to get at the list level number, you can use

        List1 = Selection.Range.ListFormat.ListLevelNumber

        • #1027471

          Sorry, I guess I am not being clear. Nothing new for me.

          I am not trying to “return” anything. I am trying restart number at, for example, “3” for a list item that is currently set to start at “1”.

          How do I do that.

          Thanks!!
          Troy

          • #1027475

            Sorry, I can’t help here. Hopefully someone else will have a suggestion (I’ll be learning something too).

    • #1027453

      (Edited by TroyWells on 06-Sep-06 19:34. )

      I am trying to reset a list item number from 1 to 3 (or another number I calculate from a variable) in the middle of a list. Do to the dummy restart styles I have at the beginning of my list and how I have to use them, the numbers are restarting prematurely. Calculating the variable is no problem. Resetting the number is. I have tried using the following code:

      Dim List1 As Long
      Dim ListNumberBefore as Integer

      Set List1 = ListGalleries(wdOutlineNumberGallery).ListTemplates(Selection.Range.ListFormat.ListTemplate.Name).ListLevels(Selection.Range.ListFormat.ListLevelNumber)
      With List1
      .StartAt = ListNumberBefore + 1
      End With

      However, I get the following error:

      Compile error. Object required.

      Please advise what I am doing wrong or if there is a better way.

      Thanks!!
      Troy

      • #1027476

        Could you simplify the code to…

        Selection.Range.ListFormat.ListTemplate.Listlevels(Selection.Range.ListFormat.ListLevelNumber).StartAt = ListNumberBefore + 1

        StuartR

        • #1027501

          This code works in that it causes no error. The problem is that it causes all the lists in the entire document to start at whatever value is set here. In other words, if I want to change the startat value from “a” to “c”, all lists at that level in the entire document now start at “c”.

          Any other ideas?

          Thanks!!
          Troy

          • #1027588

            In that case I think this is going to get very complex, as I think you will need to create a new ListTemplate with a new name for each different starting number. Unless someone else has a brighter idea.

            Do all your ListTemplates already have names that you have defined and could use in a Macro? This might make it easier.

            StuartR

            • #1027595

              I have a single list template named “myListItems”. It is a multilevel list where the first two levels are dummy list items that are tied to specific styles that help it restart.

              Thus my problem. When the styles appear, say in a table, and the list continues, it starts over at 1. I can manually change it to start at whatever I want, but I’d prefer to do it in a macro.

              Any ideas would be appreciated!!

              Thanks!!
              Troy

            • #1027601

              Please check something for me.

              When you manually restart the list at a different number, if you then go back to the Bullets and Numbering dialog box is it definitely still using the same ListTemplate as all the other similar lists?

              regards,

              StuartR

            • #1027605

              Stuart,
              I used the following:

              MsgBox Selection.Range.ListFormat.ListTemplate.Name

              on steps that had not been reset and on a step I manually reset. They both came back with the same name.

              Troy

            • #1027659

              I really have no more ideas on this one, hopefully someone more knowledgeable will turn up soon…

              StuartR

            • #1027982

              I don’t think you can use the same listtemplate to reset lists to restart at more than one number. I also can’t see a reason to actually do this either.

              If you really need to set items in the list to specific numbers then I would expect that you have to either:
              1. Create another listtemplate for that specific occurrance
              2. Use Seq fields instead of lists to do your numbering. These can be reset to any number quite easily.

            • #1027997

              Andrew,
              Thanks for your kind attention to my problem!!

              As far as why I need to reset numbering in the middle of a list, I have a single list template named “myListItems”. It is a multilevel list where the first two levels are “dummy” list items that are tied to specific styles that help numbering to restart at other levels.

              Thus my problem. When the styles appear, say in an if/then table in the middle of a list, and the list continues, it starts over at 1. I have to put some of those dummy styles in the table so I can restart substeps in the second if/then row of the table. I can manually change it to start at whatever I want, but I’d prefer to do it in a macro.

              Hey, I just had a thought. If I create a second list template and use the macro to apply that to the list items in these tables, will that list template interfere with numbering before and after the table if the numbering before and after the table use the other list template? If not, that may solve my problem. I could create a new “dummy” style to use in the if/then tables to reset numbering for the second and following if/then scenarios, and that dummy style should not restart items in my first list template since it will not appear in that template.

              What do you think, or did I lose you?

              Troy

            • #1028042

              I’m not sure that I follow what you are trying to do so here is an example of my interpretation of your requirement.
              1. Is there water in the kettle?
              2. If No, fill the kettle with water
              3. Turn on the Kettle
              2. If Yes, turn on the kettle
              4. When the kettle has boiled, turn it off

              Is that the type of logic/numbering you are trying to achieve? If not, I guess that I need to see an example document that demonstrates the logic and numbering you want to have.
              A second list template might only be good for one alternate case and so you might need to keep adding listtemplates for each ‘funny’ list.

              I would recommend investigating either using SEQ fields or Cross-references rather than multiple listtemplates as I think you will get a more usable solution that way.

            • #1028050

              OK. I can see that I would have to improve a lot to be clear as mud. Let me try.

              I have 1 listtemplate, called “mylisttemplate”. It uses the following styles/formats:

              Level 1 – paragraph style “style1” – Number format: “” (no number, just used to reset numbers on lower levels.)
              Level 2 – paragraph style “style2” – Number format: “” (no number, just used to reset numbers on lower levels.)
              Level 3 – paragraph style “style3” – Number format: “1.”
              Level 4 – paragraph style “style4” – Number format: “a.”
              Level 5 – paragraph style “style5” – Number format: “1)”

              No definitions beyond level 5 as I don’t use those in my lists.

              My situation:
              ——————————-
              1. List item 1.
              2. List item 2.
              (table that contains paragraph style “style1”. Because it contains style one, the next step restarts numbering at 1 instead of continuing a 3.

              Why does the table contain one of dummy styles, you might ask? Because the table contains two sets of substeps based on two alternative actions you could take in step 2. You could either take option 1 with sub-steps a. and b. or option 2 with sub-steps a. and b. I have to include paragraph style “style 1” to restart numbering within the table. Otherwise it would go: option 1 sub-steps a and b, then option 2 sub-steps c and d. Thus somewhere between option 1 and option two I put paragraph style “style 1” so the number restarts at the beginning of option 2. Unfortunately, this has the side effect of also restarting number in the list item immediately following the table. Thus…)

              1. List item 3.
              ——————————-

              Thus, my proposed solution is to use a second list template for all numbering that appears within tables. It would be a similar mylist template, except that I would use different dummy styles at the first two levels to restart numbering. For example:

              Level 1 – paragraph style “style6” – Number format: “” (no number, just used to reset numbers on lower levels.)
              Level 2 – paragraph style “style7” – Number format: “” (no number, just used to reset numbers on lower levels.)
              Level 3 – paragraph style “style8” – Number format: “a.”
              Level 4 – paragraph style “style9” – Number format: “1)”

              These should restart numbering on items within the table that use paragraph style “style 8 or 9” but leave list items that use the first list template and paragraph style “style 3”, “style 4” or “style 5” unchanged.

              At least that’s my theory. I’ll let you know how it turns out.

              Enjoy!!
              Troy

            • #1028064

              OK, now I see what you are doing. I see nothing wrong with your logic but you may still do it through one list template (if you wished)

              Level 1 – paragraph style “style1” – Number format: “” (no number, just used to reset numbers on lower levels.)
              Level 2 – paragraph style “style2” – Number format: “1.”
              Level 3 – paragraph style “style3” – Number format: “a.”
              Level 4 – paragraph style “style4” – Number format: “1)”
              Level 5 – paragraph style “style5” – Number format: “” (no number, just used to reset numbers on lower levels.)
              Level 6 – paragraph style “style6” – Number format: “a.” (same look as Level 3 but used in table)
              Level 7 – paragraph style “style7” – Number format: “1)” (same look as Level 3 but used in table)

    Viewing 1 reply thread
    Reply To: Resetting a number in the middle of a list (Word 2003 VBA)

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

    Your information: