从不同的文件调用宏时出错 [英] Error calling on macro from a different file
问题描述
对象不支持此属性或方法
是我正在收到的错误尝试从我当前的文件调用另一个宏。我正在循环使用几个excel工作簿,需要在我循环的文件中运行一个宏。
Sub SaveBacktestingFiles()
/ pre>
Dim wBCalc As Workbook
Dim wBRaw As Workbook
Dim wBRun As Workbook
对于每个c在Worksheets(Static)。Range(FILE_RANGE)。
Range(Date_Range)Value = c
计算
FS_Name =范围(FS_Name_Range)值
FO_RawName =范围(FO_RawName_Range)值
设置wBRun = ActiveWorkbook
Workbooks.Open文件名:=范围(FO_CalcName_Range)值,ReadOnly:= True
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs FS_Name
设置wBCalc = ActiveWorkbook
Application.Run(wBCalc&!FilterLoop)
ActiveWorkbook.Close True
下一个
End Sub
而不是:
Application.Run(wBCalc&!FilterLoop)
我尝试d
Application.Run('& FO_CalcName_Range& '!ReApplyDump)
其中包含完整路径。
我也尝试过没有运气:Application.Run('& wBCalc& ;'!ReApplyDump)
我以前有这个工作,但不能让它为我的生活工作。任何帮助是赞赏。解决方案问题是
wbCalc
是一个工作簿而不是一个字符串。因此,你尝试的连接是没有意义的。
替换
Application.Run(wBCalc&!FilterLoop)
由
Application.Run(wBCalc.Name&!FilterLoop)
无法访问您的代码
FilterLoop
,我无法测试这个,虽然它应该让你更接近你的目标。"Object doesn't support this property or method"
is the error I am getting trying to call on another macro from my current file. I am looping through several excel workbooks and need to run a macro within the files I am looping through.
Sub SaveBacktestingFiles() Dim wBCalc As Workbook Dim wBRaw As Workbook Dim wBRun As Workbook For Each c In Worksheets("Static").Range("FILE_RANGE").Cells Range("Date_Range").Value = c Calculate FS_Name = Range("FS_Name_Range").Value FO_RawName = Range("FO_RawName_Range").Value Set wBRun = ActiveWorkbook Workbooks.Open Filename:=Range("FO_CalcName_Range").Value, ReadOnly:=True Application.DisplayAlerts = False ActiveWorkbook.SaveAs FS_Name Set wBCalc = ActiveWorkbook Application.Run (wBCalc & "!FilterLoop") ActiveWorkbook.Close True Next End Sub
Instead of:
Application.Run (wBCalc & "!FilterLoop")
I triedApplication.Run ("'" & FO_CalcName_Range & "'!ReApplyDump")
which contains the full path.
I also tried with no luck:Application.Run ("'" & wBCalc & "'!ReApplyDump")
I had this work before but cant get it to work for the life of me. Any help is appreciated.解决方案The problem is that
wbCalc
is a workbook and not a string. Hence, the concatenation that you are attempting doesn't make sense.Replace
Application.Run (wBCalc & "!FilterLoop")
By
Application.Run (wBCalc.Name & "!FilterLoop")
Without access to your code for
FilterLoop
, I can't test this, though it should get you closer to your goal.这篇关于从不同的文件调用宏时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!