vba 运行时错误“438”对象不支持此属性或方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21902577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run-time error '438' Object doesn't support this property or method
提问by Mr.Beto
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"
我有一个带有 VBA 的宏,但我的程序失败了。Visual Basic 应用程序向我展示了这个错误:“运行时错误‘438’对象不支持此属性或方法”
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 ?
在行Sheets(i).Cells.Replace What:="C:\", Replacement:="C:\Gestion\" 中,我的程序不起作用。问题是什么 ?
My excel file it has the Microsoft Excel 97-2003 Format.
我的 excel 文件具有 Microsoft Excel 97-2003 格式。
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!
谢谢!
采纳答案by Dmitry Pavliv
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