View Single Post
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Tom Tom is offline
external usenet poster
 
Posts: 61
Default adding quotation marks around a selection (can you help me tweak this code?)

This is a long shot here, but I figured I'd try this forum for help.

I have a macro that takes a hyperlink that says, for example,
Performing Advanced Searches and it converts this to Performing
Advanced Searches on page 7. (In other words, it adds a page number to
the cross reference).

The only problem is that our style guide would have us write it with
quotation marks, like this: See "Performing Advanced Searches" on page
7.

The macro is kind of long. I was hoping someone on this forum might
advise me how to tweak the code so that it includes the quotation marks
around the selection. Thanks.

Sub CrossReferences()
' 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