PDA

View Full Version : Find superscript numbers with a prefix of "REF"



AlexandarR
05-19-2015, 07:18 AM
Hi!

I have to find "Ref.2", etc. i.e., default text "Ref." with superscript numbers.

I can find "Ref." and superscript numbers separately. But, I don't know, how to find them combined.

Anybody please help!

Regards
Alex

gmaxey
05-19-2015, 05:30 PM
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "Ref."
While .Execute
Do While oRng.Characters.Last.Next Like "[0-9]" _
And oRng.Characters.Last.Next.Font.Superscript
oRng.MoveEnd wdCharacter, 1
Loop
oRng.Select 'Do something with the found range.
oRng.Collapse wdCollapseEnd
Wend
End With
lbl_Exit:
Exit Sub
End Sub

AlexandarR
05-20-2015, 06:21 AM
Thank you for come forward to help!




Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.range
Set oRng = ActiveDocument.range
With oRng.Find
.Text = "Ref. "
While .Execute
Do While oRng.Characters.Last.Next Like "[0-9]" _
And oRng.Characters.Last.Next.Font.Superscript
oRng.MoveEnd wdCharacter, 1
Loop
oRng.Select 'Do something with the found range.
oRng.HighlightColorIndex = wdTurquoise
oRng.Font.Color = wdColorPink
oRng.Comments.Add oRng, "CE: Reference callouts should not be in superscript."
oRng.Collapse wdCollapseEnd
Wend
End With
lbl_Exit:
Exit Sub
End Sub


This code finds the "Ref."+number with/without superscript. But, I need to find only superscript numbers with text "Ref." Can you please look into this...

Regards
Alex

gmaxey
05-20-2015, 07:47 AM
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "Ref."
While .Execute
Do While oRng.Characters.Last.Next Like "[0-9]" _
And oRng.Characters.Last.Next.Font.Superscript
oRng.MoveEnd wdCharacter, 1
Loop
If Len(oRng.Text) > 4 Then
oRng.Select 'Do something with the found range.
End If
oRng.Collapse wdCollapseEnd
Wend
End With
lbl_Exit:
Exit Sub
End Sub

AlexandarR
05-20-2015, 07:57 AM
Thanks a lot!!!

It works fine...!!!

Regards
Alex