Thread: [Solved] Find & Replace Unique word
View Single Post
 
Old 05-17-2017, 01:43 AM
raghugada raghugada is offline Windows XP Office 2007
Novice
 
Join Date: Apr 2017
Posts: 21
raghugada is on a distinguished road
Default wildcards throwing error

Distortion using wildcard.zip

I have tried using wildcards but getting error i have attached the error snap shot
I have attached the macro, word file and excel file

Code:
Sub RemoveShreeLipiDistortionUsingWildCards()
    
    Dim objExcel As Object
    Set objExcel = CreateObject("Excel.Application")

    Set exWb = objExcel.Workbooks.Open(ActiveDocument.path + "\List of ShreeLipi Distortion (1).xlsx")
    Dim counter As Integer
    counter = 1000 'exWb.Worksheets(1).Rows.Count
    Dim i As Integer
    Dim oRng As Range
    
    'For i = 250 To counter
    For i = 2 To counter
        If exWb.Worksheets(1).Range("A" & i) = "" Then
            Exit For
        End If
        Set oRng = ActiveDocument.Range
        With oRng.Find
            .Text = "<" + Replace(exWb.Worksheets(1).Range("A" & i), "^", "^^") + ">"
            .Replacement.Text = Replace(exWb.Worksheets(1).Range("B" & i), "^", "^^")
            .MatchCase = True
            '.MatchWholeWord = True
            .MatchWildcards = True
            .MatchCase = True
            .Execute Replace:=wdReplaceAll
        End With
    Next i
    exWb.Close
    Set exWb = Nothing
    Set objExcel = Nothing
End Sub

Last edited by macropod; 05-17-2017 at 10:38 PM. Reason: Added code tags