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

    Formatting TOC Page numbers (VBA Word 2000)

    This only happens if I use the h option in the TOC field. I need to be able to add a character style to the page numbers in a TOC. WithOUT the h in the TOC field, I can do VBA to select just the page number. However, I can find no way to do this WITH the h option.

    Thanks for your help!!
    Troy

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

    Re: Formatting TOC Page numbers (VBA Word 2000)

    Since noone else seemed to have an answer, I found a clunky but functional workaround I thought I would share.

    The problem I was having was selecting just the page numbers at the end of the paragraphs in the TOC as well as some chapter numbers that appeared at the beginning of TOC 1 paragraphs. The problem with doing this with the hyperlink option (h) enabled is that you cannot select the first or last character of a paragraph. Without that option you can select whatever you want.

    My workaround:

    1. Update the table of contents.

    2. Temporarily unlink the field by selecting the entire paragraph and running the command:

    Selection.Fields.Unlink

    3. Copy the first or last character as needed.

    4. ActiveDocument.Undo 1 (which reverts back to the hyperlink functionality)

    5. Paste the character either just after the first character or just before the last character depending on what I copied.

    6. Now I can select all but the first or last character and apply whatever formatting I want.

    I also found I could use a Find, looking for "^t^#" (without wildcards ONLY). This finds the tab before the page number and the entire page number regardless of how many digits the page number is. Perhaps this little advantage is a result of the way the hyperlink or fields are constructed. NOTE: I could not do a replace to add formatting as you would think, but I could apply formatting, such as a style directly after the find. Thus, I could use if/then or while selection.find.found to apply the formatting as needed.

    If you can improve on this, please let me know. It works, but I know it's not the prettiest solution in the world.

    Thanks!!
    Troy

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Formatting TOC Page numbers (VBA Word 2000)

    The lack of reply wasn't due to lack of interest, but because I have had the same problem and not been able to solve it either.

    StuartR

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

    Re: Formatting TOC Page numbers (VBA Word 2000)

    I did not mean to imply there had been no interest. I just didn't see any answers. I assume when that happens I've just put out a rare stumper. If you happen to find any better way, please let me know. Otherwise, enjoy the solution!!

    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
  •