Page Reference Codes and Bookmarks or Styles

G

Guest

I'm doing a directory of attorney bios. There are 245 attorneys. I need to
create a TOC and an Index. The TOC is firstname/lastname/location in order
by specific sections and specific attorneys (partners 1st, etc.) The Index
will be by lastname,/first name.

I found some code to automatically bookmark a style. The names are
formatted with a style. Next I need to create the pageref codes. I have a
macro to list all the bookmark names.

Is there a way to automate creating the pageref code by either copying the
name from my bookmark list, then create a pageref code assigning the copied
bookmark name that was copied? Or is there a way to auto pageref each name
using the style?

I put together the code below, but doesn't work. I thought I could assign
the copied text to a variable, then assign the variable text to the page ref
code.

Sub PageReference_TEST()
'
' PageReference_TEST Macro
' Macro recorded 6/12/2006 by cm9125
'
Dim aText As String

Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Copy
Selection.HomeKey Unit:=wdLine

aText = Selection.Text

Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"PAGEREF" & aText, PreserveFormatting:=True
Debug.Print aText
End Sub
 
J

Jezebel

You don't need to do any of this. You can create a TOC directly from any
styles you like (or from TC fields that you insert): either way, the page
numbers will be inserted automatically. Likewise, index entries also pick up
the page numbers automatically.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top