运行时错误'438'对象不支持此属性或方法

时间:2014-02-20 08:49:40

标签: excel vba

我有一个带VBA的宏,但我的程序失败了。 Visual Basic应用程序向我显示此错误:“运行时错误'438'对象不支持此属性或方法”

我的代码是:

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

Sheets(i).Cells.Replace What:=“C:\”,Replacement:=“C:\ Gestion \” ,我的程序不起作用。有什么问题?

我的Excel文件它具有Microsoft Excel 97-2003格式。

最后,我可以解决这个问题。

我的新代码是:

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

谢谢!

1 个答案:

答案 0 :(得分:0)

您似乎有图表表。尝试按如下方式更改代码:

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