vbs触发宏不工作

时间:2016-03-03 21:32:01

标签: vbscript

我写了一个宏来刷新工作簿并仅在目录值中保存另一个工作簿中的选定工作表(删除工作表中的所有公式)

Sub create()

ActiveWorkbook.RefreshAll
ActiveWorkbook.Save
Dim WS As Worksheet
Application.DisplayAlerts = False
For Each WS In Sheets(Array("Product Team", "Marketing Team"))
WS.UsedRange.Value2 = WS.UsedRange.Value2
Next WS
Set WS = Nothing

ChDir "\\Mac\Home\Desktop" ' Name folder

ActiveWorkbook.SaveAs Filename:= _
    "\\Mac\Home\Desktop\test.xlsx" _
    , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False 
End Sub

当我运行宏时,这个工作正常,然后我写了一个vbs来触发宏运行而不打开电子表格

Set fso = CreateObject("Scripting.FileSystemObject")
curDir = fso.GetAbsolutePathName(".")
Set myxlApplication = CreateObject("Excel.Application")
myxlApplication.Visible = false
Set myWorkBook = myxlApplication.Workbooks.Open("\\Mac\Home\Desktop\Testbook.xlsm" ) 'Change to the actual workbook that has the Macro   
myWorkBook.Application.Run "Module1.create()"
myxlApplication.Quit

我不知道为什么vbs不起作用,它的运行但没有得到保存,我的原始工作簿消除了所有的公式。

1 个答案:

答案 0 :(得分:0)

调用没有括号的宏,这应该可以工作

myWorkBook.Application.Run "Module1.create"