Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Text preceeding number format (Word 97/2000)

    I would like to have a macro that alters the text that preceeds a number format, e.g. ARTICLE I. More to the point, I would like to alter existing text that exceeds the allowable number of characters that can be entered into the Number Format field on the Customize Outline Numbered List dialog. When creating the original setup, I set the text to, for example, Response to Question Number (follower by the number). The user needs to change that to Responde to Interrogatory Number.... but cannot enter text of that length.

    How would I approach the editing process? I need to get to the appropriate list template that is linked to the style.

    Thanks.
    Richard Barrett

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Text preceeding number format (Word 97/2000)

    Hi Richard,

    This turns out to be a really good illustration of something that you can do with VBA, that can't be done directly within the Word interface.

    If I try to add extra characters into the text before the autonumber, via the Customize numbering dialog, it permits me to type lots of letters, but when I click OK, only about 20 or so display before the number in the document.

    This would seem to point to a built-in limit in Word, but it turns out you can substantially exceed that limit by using VBA.

    Getting at the code related to your list template and styles is actually ridiculously easy:

    Click an insertion point in a paragraph that is an example of the first level of your outline numbered list.
    Now start the macro recorder, and record a macro of the following steps:
    Click on Format > Bullets and Numbering > Customize.
    The Customize dialog will display - simply click on OK.
    And then OK again to dismiss the Bullets and Numbering dialog.

    Stop the macro recorder.
    Now go look at your code.
    You will have many dozens of lines of code, that are a code 'template' or representation of the list template.

    Now look for the line of code, toward the very beginning, that controls the text and number for the first level; it will look something like this:

    .NumberFormat = "Article %1"

    Now, as a demonstration, type a whole bunch of words, just before the word Article (but inside the opening quotation mark).

    Now go back to your Word document, place the insertion point in that first level paragraph, and run the macro you just recorded and altered. Bingo! - you've got an extra long text before your autonumber. (It may be that even with code, there is some built-in limit to the length of this, like 128 or 255, but not sure.).

    Now that you've zeroed in on the line of code that controls the text for the autonumber, you can use string variables to enable this code to change, at runtime.

    For example (pseudocode):

    Dim strLev1Text As String

    If 'depending on conditions Then
    strLev1Text = "Article"
    Else:
    strLev1Text = "Repond to Interrogatory Number"
    End If

    and the above line of code would look like this:

    .NumberFormat = strLev1Text & " %1"

    This should get you pointed in the right direction...

    Gary

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Text preceeding number format (Word 97/2000)

    Hi Gary,

    Thanks for your reply. I had already been working with the information you sent me, and it's at that point that I got stumped.

    In order to edit the text, I need to know (or at least I THINK I need to know) the index of the ListTemplate. In the example below, it's 6.

    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(6).ListLevels(1)
    .NumberFormat = "Question no. %1."

    It's easy enough for me to write a macro that will alter line 2 above (.NumberFormat), but how do I discern the index of the ListTemplate before I proceed? That is what's giving me all the trouble.

    Thanks again,
    Richard

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Text preceeding number format (Word 97/2000)

    Hi Richard,

    I understand the problem, and figure there may be a direct and reliable solution to this, but I don't know it!

    Addressing the list template, by referring to its gallery position, can be dangerous because the gallery position may differ from user to user.

    My workaround is a little clumsy, but it is absolutely reliable: just ensure that a paragraph that has the style that corresponds to level 1 of the outline numbering scheme, is selected (really just need an IP), before the rest of the code runs to alter the list template. This ensures that the correct list template is addressed.

    You can have the code find and select the required paragraph, then run the numbering code, and finally return to the original location before the macro was run - that way it's pretty seamless for the user.

    Gary

  5. #5
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Text preceeding number format (Word 97/2000)

    Hi Gary,

    I guess I'm not understanding you. I realize that the list template index is going to change from document to document, so I'm trying to retrieve that index. Without it, I don't know how I'd write the following code, where for our purposes, x = the ListTemplate index.

    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(x).ListLevels(1)
    .NumberFormat = "Question no. %1."

    What is the parent object of .NumberFormat other then the above code where the index of ListTemplate is required.

    Or are you suggesting that I simply select this paragraph (which I could find by looking for a paragraph with that sytyle) and reapply the numbering.... "from scratch" so to speak?

    Thanks,
    Richard

Posting Permissions

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