njaim
11-03-2012, 08:09 PM
I'm trying to get a microsoft word macro that goes through a selection of numbers that are superscripts and then turns them into a hyperlink to a bookmark in the document...
So if there is a 45 as a superscripted number, the macro selects it, changes it into a hyperlink with "#ref_c3n" & currentnumber and then the text to display is currentnumber as well. Only problem I'm having is that I don't know how to get the text to display as a superscript after that.
It only does this to the number specified (because it will start over at 1 after that)
Here's what I have now, anyone know how to help?
Sub TestMe()
Dim current
current = 39
abba:
If current < 146 Then
Selection.Find.ClearFormatting
With Selection.Find.Font
.Superscript = True
.Subscript = False
End With
With Selection.Find
.Text = current
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="", _
SubAddress:="#ref_c3n" & current, ScreenTip:="", TextToDisplay:=current
current = current + 1
Else
End
End If
GoTo abba
End Sub
So if there is a 45 as a superscripted number, the macro selects it, changes it into a hyperlink with "#ref_c3n" & currentnumber and then the text to display is currentnumber as well. Only problem I'm having is that I don't know how to get the text to display as a superscript after that.
It only does this to the number specified (because it will start over at 1 after that)
Here's what I have now, anyone know how to help?
Sub TestMe()
Dim current
current = 39
abba:
If current < 146 Then
Selection.Find.ClearFormatting
With Selection.Find.Font
.Superscript = True
.Subscript = False
End With
With Selection.Find
.Text = current
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="", _
SubAddress:="#ref_c3n" & current, ScreenTip:="", TextToDisplay:=current
current = current + 1
Else
End
End If
GoTo abba
End Sub