Consulting

Results 1 to 8 of 8

Thread: Find Font Colour or Strikethrough

  1. #1

    Find Font Colour or Strikethrough

    Hello All,

    What a great forum! You have been so helpful to me. I have another question. Is it possible to get a macro to find the next occurrence of either red or blue text or strikethrough? I want it to select the next occurrence of either of these attributes.

    Thank you!
    Bernie

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    Something like this:

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    Dim oRng As Word.Range
    Dim oCol As Collection
    Dim lngIndex As Long
      Set oCol = New Collection
      For lngIndex = 1 To 3
        Set oRng = ActiveDocument.Range
        oRng.Start = Selection.End
        With oRng.Find
          .Wrap = wdFindStop
          Select Case lngIndex
            Case 1: .Font.Color = wdColorBlue
            Case 2: .Font.Color = wdColorRed
            Case 3: .Font.StrikeThrough = True
          End Select
          If .Execute Then
            If oCol.Count = 0 Then
              oCol.Add oRng
            Else
              If oRng.Start < oCol.Item(1).Start Then
                oCol.Remove 1
                oCol.Add oRng
              End If
            End If
          End If
        End With
      Next
      If oCol.Count > 0 Then
        oCol.Item(1).Select
      End If
    lbl_Exit:
      Exit Sub
      
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    Awesome! Works perfectly. Thanks so much.

  4. #4
    The macro is working great unless the red text happens to be in a table. If the macro finds red text in a table it won't go any further. Any suggestions?

  5. #5
    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
        Dim oCol As Collection
        Dim lngIndex As Long
        Set oCol = New Collection
        For lngIndex = 1 To 3
            Set oRng = ActiveDocument.Range
            oRng.Start = Selection.End
            With oRng.Find
                .Wrap = wdFindStop
                Select Case lngIndex
                Case 1: .Font.Color = wdColorBlue
                Case 2: .Font.Color = wdColorRed
                Case 3: .Font.StrikeThrough = True
                End Select
                Do While .Execute
                    If oCol.Count = 0 Then
                        If oRng.Start > Selection.End Then
                          oCol.Add oRng
                          Exit Do
                        End If
                    Else
                        If oRng.Start < oCol.Item(1).Start Then
                            oCol.Remove 1
                            oCol.Add oRng
                            Exit Do
                        End If
                    End If
                Loop
            End With
        Next
        If oCol.Count > 0 Then
            oCol.Item(1).Select
        End If
    lbl_Exit:
        Exit Sub
         
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  6. #6
    Thank you but it still gets stuck in the table...

  7. #7
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    "The table." What table? It doesn't get stuck in my table.
    Greg

    Visit my website: http://gregmaxey.com

  8. #8
    It must be something weird in my document. I tried it in a new document with a table and it worked fine. Thanks again!

Posting Permissions

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