0
votes

I have a macro with VBA, but my program fail. The Visual Basic Application show me this missatge : "Run-time error '438' Object doesn't support this property or method"

My code is :

Sub MACRO()
    bAlerts = Application.DisplayAlerts
    Application.DisplayAlerts = False
    For i = 1 To Sheets.Count
    ***Sheets(i).Cells.Replace What:="C:\", Replacement:="C:\Gestion\"***
    Next
    Application.DisplayAlerts = bAlerts
End Sub

In the line Sheets(i).Cells.Replace What:="C:\", Replacement:="C:\Gestion\", my program doesn't work. What is the problem ?

My excel file it has the Microsoft Excel 97-2003 Format.

Finally, I could fix this.

My new code is :

Attribute VB_Name = "RemplazoString"
Sub MACRO()
    Dim Sht As Worksheet
    bAlerts = Application.DisplayAlerts
    Application.DisplayAlerts = False
    For Each Sht In Worksheets
    Sht.Cells.Replace What:="C:\", Replacement:="C:\Gestion\", LookAt:=xlPart, MatchCase:=False
    Next
    Application.DisplayAlerts = bAlerts
End Sub

Thanks!

1
do you have Chart sheets?Dmitry Pavliv
Yes, I find my error! Does it! Thank you!Mr.Beto

1 Answers

0
votes

It seems that you have chart sheets. Try to change your code as follows:

Sub MACRO()
    bAlerts = Application.DisplayAlerts
    Application.DisplayAlerts = False
    For i = 1 To Worksheets.Count
        Worksheets(i).Cells.Replace What:="C:\", Replacement:="C:\Gestion\"
    Next
    Application.DisplayAlerts = bAlerts
End Sub