【发布时间】:2017-09-03 08:49:27
【问题描述】:
我正在尝试使用宏执行“全部刷新”(如下图所示):
以下是宏(在Module1中编写):
Sub Workbook_RefreshAll()
ActiveWorkbook.RefreshAll
End Sub
然后我正在编写如下的 VBScript:
'Code should be placed in a .vbs file
Set objExcel = CreateObject("Excel.Application")
Set book = objExcel.Workbooks.Open("excel.xlsm", , True)
WScript.Echo "Executing RefreshAll"
objExcel.Application.Run "'excel.xlsm'!Module1.Workbook_RefreshAll"
WScript.Echo "Executing Mailing"
objExcel.Application.Run "'excel.xlsm'!ThisWorkbook.Mail"
objExcel.DisplayAlerts = False
objExcel.Application.Quit
Set objExcel = Nothing
但它不会刷新工作簿。
【问题讨论】:
-
宏没有被调用,还是没有刷新你想要的工作簿?添加一些调试输出到
Workbook_RefreshAll(例如Debug.Print ActiveWorkbook.Name)。 -
所以,即使我手动运行宏,文件也不会刷新。
-
你把我建议的命令放到宏里了吗?是否输出要刷新的工作簿名称?