Results 1 to 20 of 92

Thread: LinkToPrevious

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,411
    Location
    glencoe,

    Yes using wildcards does present its problems. This doesn't look as clean, but you can avoid them if you want:

    Sub ScratchMacro2()
    'A basic Word macro coded by Greg Maxey
    Dim oSection As Section
    Dim oHF As HeaderFooter
    Dim oRng As Range, oTextRng As Range
    Dim oRng2 As Range
    Dim strOTag As String, strCTag As String
        
      strOTag = "##"
      strCTag = "**"
      For Each oSection In ActiveDocument.Sections
      For Each oHF In oSection.Headers
        With oHF
          If .LinkToPrevious = False Or oSection.Index = 1 Then
            Set oRng = oHF.Range
              With oRng.Find
                .Text = strOTag
                 While .Execute
                   Set oRng2 = oHF.Range
                   oRng2.Start = oRng.End
                   With oRng2.Find
                     .Text = strCTag
                     If .Execute Then
                       Set oTextRng = oRng.Duplicate
                       oTextRng.Collapse wdCollapseEnd
                       oTextRng.End = oRng2.Start
                       oRng.Delete
                       oRng2.Delete
                       If Not InStr(oTextRng.Text, strOTag) > 0 Then
                         oTextRng.HighlightColorIndex = wdBrightGreen
                       Else
                         oTextRng.HighlightColorIndex = wdRed
                       End If
                    End If
                   End With
                  Wend
                End With
              End If
            End With
        Next oHF
      Next oSection
    End Sub
    Last edited by gmaxey; 02-09-2014 at 02:26 PM.
    Greg

    Visit my website: http://gregmaxey.com

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
  •