Invoke vba doesnt work with replace activity in excel

This is the macro :

Sub Macrotiret()

’ Macrotiret Macro


Cells.Select
Range(“A:Z”).Activate
Selection.Replace What:=" – “, Replacement:=” - ", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End Sub

I guess you have just recorded the macro in Excel and invoking it from UiPath.

Please change the code into the following.

Sub ReplaceText()
 
 'sheet1 is the sheet name you are going to replace
 'A:Z is the range the data will be replaced

  sheet1.Range("A:Z").Replace What:=" – ", Replacement:=" - ", LookAt:=xlPart, _
  SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
  ReplaceFormat:=False

End Sub

For testing purpose, run the macro manually directly in Excel and check.
If it is running, the invoke it from UiPath.

Regards,
Karthik Byggari

1 Like