Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Closed Thread
 
Thread Tools Display Modes
  #16  
Old 05-15-2017, 10:17 PM
macropod's Avatar
macropod macropod is offline Find & Replace Unique word Windows 7 64bit Find & Replace Unique word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,342
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Wildcards have no particular difficulty with special characters; it's your implementation that's the issue. Put plainly, if the character is not an ASCII character (i.e. it's a Unicode character), you can't include it in a simple string - you must specify it via its ChrW value.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
  #17  
Old 05-17-2017, 01:43 AM
raghugada raghugada is offline Find & Replace Unique word Windows XP Find & Replace Unique word Office 2007
Novice
Find & Replace Unique word
 
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
  #18  
Old 05-17-2017, 04:17 PM
macropod's Avatar
macropod macropod is offline Find &amp; Replace Unique word Windows 7 64bit Find &amp; Replace Unique word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,342
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

There are no attachments to your post - just some code you haven't used the code tags for.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
  #19  
Old 05-17-2017, 10:32 PM
raghugada raghugada is offline Find &amp; Replace Unique word Windows XP Find &amp; Replace Unique word Office 2007
Novice
Find &amp; Replace Unique word
 
Join Date: Apr 2017
Posts: 21
raghugada is on a distinguished road
Default

this is the zip file i have added as attachment in the beginning
distortion.zip
  #20  
Old 05-17-2017, 11:12 PM
macropod's Avatar
macropod macropod is offline Find &amp; Replace Unique word Windows 7 64bit Find &amp; Replace Unique word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,342
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Your Excel Find list contains characters that, when used for wildcards, are 'special' characters (e.g. (){}[]<>-@\!?*^). If you need to Find the literal characters, therefore, you need to prefix each of them a \, except for the ^ which must be replaced with ^094. That can all be done in your code via a simple string replacement loop without changing the Excel data. For example:
Code:
Sub RemoveShreeLipiDistortionUsingWildCards()
Application.ScreenUpdating = False
Dim objExcel As Object, Counter As Long, i As Long, j As Long
Dim StrFnd As String: StrRep As String: Const StrEsc As String = "(){}[]<>-@\!?*"
    
Set objExcel = CreateObject("Excel.Application")
Set exWb = objExcel.Workbooks.Open(ActiveDocument.Path + "\List of ShreeLipi Distortion (1).xlsx")
With exWb.Worksheets(1)
  Counter = .Range("A" & .Cells.SpecialCells(11).Row).End(-4162).Row ' 11 = xlCellTypeLastCell, -4162 = xlUp

  For i = 2 To Counter
    StrFnd = Replace(.Range("A" & i), "^", "^^")
    StrRep = Replace(.Range("B" & i), "^", "^^")
    For j = 1 To Len(StrEsc)
      StrFnd = Replace(StrFnd, Mid(StrEsc, i, 1), "\" & Mid(StrEsc, i, 1))
    Next
    StrFnd = Replace(StrFnd, "^", "^094")
    With ActiveDocument.Range.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Forward = True
      .Format = False
      .MatchWildcards = True
      .Wrap = wdFindContinue
      .Text = "<" & StrFnd & ">"
      .Replacement.Text = StrRep
      .Execute Replace:=wdReplaceAll
    End With
  Next i
  .Close False
End With
Set exWb = Nothing: Set objExcel = Nothing
Application.ScreenUpdating = True
End Sub
A non-wildcard equivalent would be:
Code:
Sub RemoveShreeLipiDistortionUsingWildCards()
Application.ScreenUpdating = False
Dim objExcel As Object, Counter As Long, i As Long, j As Long, StrFnd As String, StrRep As String
    
Set objExcel = CreateObject("Excel.Application")
Set exWb = objExcel.Workbooks.Open(ActiveDocument.Path + "\List of ShreeLipi Distortion (1).xlsx")
With exWb.Worksheets(1)
  Counter = .Range("A" & .Cells.SpecialCells(11).Row).End(-4162).Row ' 11 = xlCellTypeLastCell, -4162 = xlUp

  For i = 2 To Counter
    StrFnd = Replace(.Range("A" & i), "^", "^^")
    StrRep = Replace(.Range("B" & i), "^", "^^")
    With ActiveDocument.Range.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Forward = True
      .Format = False
      .MatchCase = True
      .MatchWholeWord = True
      .MatchWildcards = False
      .Wrap = wdFindContinue
      .Text = StrFnd
      .Replacement.Text = StrRep
      .Execute Replace:=wdReplaceAll
    End With
  Next i
  .Close False
End With
Set exWb = Nothing: Set objExcel = Nothing
Application.ScreenUpdating = True
End Sub
Still, given what your Excel data are, I can't see the need for wildcards. Neither can I see the purpose of your:
Replace(exWb.Worksheets(1).Range("A" & i), "^", "^^")
and:
Replace(exWb.Worksheets(1).Range("B" & i), "^", "^^")
If you need to use double-carets, why not include them in the Excel data?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
  #21  
Old 05-23-2017, 04:06 AM
raghugada raghugada is offline Find &amp; Replace Unique word Windows XP Find &amp; Replace Unique word Office 2007
Novice
Find &amp; Replace Unique word
 
Join Date: Apr 2017
Posts: 21
raghugada is on a distinguished road
Default

As you said me earlier that tracking is not working for step replacement
so that u suggested me to use wildcards

this code is for non wildcards
Replace(exWb.Worksheets(1).Range("A" & i), "^", "^^")
and:
Replace(exWb.Worksheets(1).Range("B" & i), "^", "^^")
  #22  
Old 05-23-2017, 07:13 PM
macropod's Avatar
macropod macropod is offline Find &amp; Replace Unique word Windows 7 64bit Find &amp; Replace Unique word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,342
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Your post makes no sense. I have given you two macros that will work equally well - with or without wildcards. Simply telling me that part of your code is for non-wildcards doesn't for a moment explain why you're using it or, if it's needed, why you don't just change the data source.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
  #23  
Old 05-24-2017, 01:21 AM
raghugada raghugada is offline Find &amp; Replace Unique word Windows XP Find &amp; Replace Unique word Office 2007
Novice
Find &amp; Replace Unique word
 
Join Date: Apr 2017
Posts: 21
raghugada is on a distinguished road
Default Run-time error '5560'

I have added the code below which still showing me the same error



In the excel sheet there are 725 rows try for all the of the rows
try to test fully on your end fully then
Try to execute fully on your end

If you can't solve the problem then tell me clearly don't blame me or rotate
try to understand the problem.

Simply assuming the problem and giving me a solution.
First try to test on your end and then tell me
If you are honestly testing you will get error

Be prompt in your work donot simply guess and reply

Sub RemoveShreeLipiDistortionUsingWildCards1()
Application.ScreenUpdating = False
Dim objExcel As Object, Counter As Long, i As Long, j As Long
Dim StrFnd, StrRep As String
Const StrEsc As String = "(){}[]<>-@\!?*"
Dim iDataRow As Long
Set objExcel = CreateObject("Excel.Application")
Set exWb = objExcel.Workbooks.Open(ActiveDocument.path + "\List of ShreeLipi Distortion (1).xlsx")
With exWb.Worksheets(1)
Counter = .Cells(.Rows.Count, 1).End(-4162).Row
'Counter = .Range("A" & .Cells.SpecialCells(11).Row).End(-4162).Row ' 11 = xlCellTypeLastCell, -4162 = xlUp
'MsgBox Counter
'MsgBox iDataRow
'End
For i = 2 To Counter
StrFnd = Replace(.Range("A" & i), "^", "^^")
StrRep = Replace(.Range("B" & i), "^", "^^")
For j = 1 To Len(StrEsc)
StrFnd = Replace(StrFnd, Mid(StrEsc, j, 1), "\" & Mid(StrEsc, j, 1))
StrRep = Replace(StrRep, Mid(StrEsc, j, 1), "\" & Mid(StrEsc, j, 1))
Next
'MsgBox StrRep
StrFnd = Replace(StrFnd, "^", "^094")
With ActiveDocument.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Format = False
.MatchWildcards = True
.Wrap = wdFindContinue
.Text = "<" & StrFnd & ">"
.Replacement.Text = StrRep
.Execute Replace:=wdReplaceAll
End With
Next i
'exWb.Close False
End With
Set exWb = Nothing: Set objExcel = Nothing
Application.ScreenUpdating = True
End Sub
Attached Images
File Type: jpg Run-time error '5560'.JPG (12.2 KB, 16 views)
  #24  
Old 05-24-2017, 02:09 AM
macropod's Avatar
macropod macropod is offline Find &amp; Replace Unique word Windows 7 64bit Find &amp; Replace Unique word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,342
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by raghugada View Post
IIf you can't solve the problem then tell me clearly don't blame me or rotate
try to understand the problem.

Simply assuming the problem and giving me a solution.
First try to test on your end and then tell me
If you are honestly testing you will get error

Be prompt in your work donot simply guess and reply
You are an extremely rude person. Thread closed.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Closed Thread



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find &amp; Replace Unique word MS Word 2016 Find and Replace BillM Word 2 03-14-2017 10:49 AM
Find &amp; Replace Unique word Need help using Find & Replace (MS Word) BZee Word 9 02-16-2015 05:45 PM
Replace each heading with a unique numeric value amitkapoor Word 7 05-06-2013 03:29 AM
Find &amp; Replace Unique word Word Find and Replace Query bthart Word 1 12-29-2011 12:45 AM
Find &amp; Replace Unique word Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:08 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft