View Single Post
 
Old 02-10-2016, 01:59 PM
Cosmo Cosmo is offline Windows Vista Office 2007
Competent Performer
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

Here's the final code I am using:

Code:
    Dim oDoc As Document    
    Dim rng As Word.Range
    Dim rngISIDrugName As Word.Range
    Dim pgNumber As Integer
    Dim currentPageNumber As Integer
    
    Set oDoc = ActiveDocument
    Set rng = oDoc.Range
    
    With rng
        With .Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .MatchWildcards = True
            .Replacement.Text = "BRAND\1"
            .Forward = True
            .Text = "BRAND®([!\(]{1,5})\([!\)]@\)"
            .Execute
        End With
        While .Find.Found = True
            pgNumber = .Information(Word.WdInformation.wdActiveEndAdjustedPageNumber)
            If pgNumber = currentPageNumber Then
                .Find.Execute Replace:=wdReplaceOne
                ' NOTE - Need to remove extra space here!
                If (Right(.Text, 1) = " ") Then
                    .Text = Left(.Text, Len(.Text) - 1)
                End If
                .Collapse wdCollapseEnd
            Else
                currentPageNumber = pgNumber
            End If
            .Find.Execute
        Wend
    End With
Reply With Quote