C
C Marshall
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
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