Consulting

Results 1 to 5 of 5

Thread: Find superscript numbers with a prefix of "REF"

  1. #1

    Find superscript numbers with a prefix of "REF"

    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

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    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
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    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

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    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
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    Thanks a lot!!!

    It works fine...!!!

    Regards
    Alex

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •