View Single Post
  #15   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Tom Tom is offline
external usenet poster
 
Posts: 61
Default Use DocVariable field to initiative numbering?

As far as cross references go, I found a really cool macro at Peter
Grainge's site (www.grainge.org under RoboHelp Printed Documentation
Print Issues). Here's what it does: In your document, if you have hyperlinks to different heading titles, and if those hyperlinks have the same wording as the headings they point to, the macro converts the hyperlink into a cross reference with a page number. For example "For more information, see Heading Styles." (where Heading Styles is a hyperlink to another heading) becomes "For more information, see Heading Styles on page 5 (or whatever page that heading happens to be at).


I found just one little problem with the macro code, but my VB friend
told me to comment out a little bit of code after the word true about
50 lines down, and then it worked. I'm posting the revised code here in
case anyone else is interested:

Sub RebuildLinks()
' This bit added to set Smart Cut and Paste off while macro runs
' Thanks to JScher at Woody's Lounge, www.wopr.com

Dim blnSmartCutAndPaste As Boolean
blnSmartCutAndPaste = Options.SmartCutPaste
Options.SmartCutPaste = False

' This macro written by Tannis Turnbull. RH Forum

Dim myHeadings() As String
'Dim myPageNumbers() As String
Dim i As Integer

'store all heading information
myHeadings = ActiveDocument.GetCrossReferenceItems(wdRefTypeHea ding)

'move the cursor to section 3
Selection.HomeKey Unit:=wdStory
Selection.Move wdSection, 2

'search for text with hyperlink style
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Hyperlink")

With Selection.Find
..Text = ""
..Replacement.Text = ""
..Forward = True
..Wrap = wdFindContinue
..Format = True
..MatchCase = False
..MatchWholeWord = False
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False

..Execute FindText:="", Format:=True
While .Found = True
'loop around refs to find the right one and update link
For i = 1 To UBound(myHeadings)
If Selection = Trim(myHeadings(i)) Then
'update the style with a real link and page info
Selection.Delete
Selection.InsertCrossReference ReferenceType:="Heading",
ReferenceKind:= _
wdContentText, ReferenceItem:=CStr(i), InsertAsHyperlink:=True, _
IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" "
' in Word XP amend the line above to IncludePosition:=False
Selection.TypeText Text:=" on page "
Selection.InsertCrossReference ReferenceType:="Heading",
ReferenceKind:= _
wdPageNumber, ReferenceItem:=CStr(i), InsertAsHyperlink:=True ', _
'IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" "
' in Word XP amend the line above to IncludePosition:=False
End If
Next i
..Execute
Wend
End With
' Next line added as part of JScher's change, restores setting to what
user had before.
Options.SmartCutPaste = blnSmartCutAndPaste
End Sub