尝试这个
Dim objExcel, objWorkbook
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Folder\Test_PO.xls")
objExcel.Visible = True
objExcel.Run "Data_Analysis"
objWorkbook.Close
objExcel.Quit
Set objWorkbook = Nothing
Set objExcel = Nothing
WScript.Echo "Finished."
WScript.Quit
编辑
如果宏在一个模块中,那么上面的内容会有所帮助。如果宏在工作表中说,Sheet1 然后替换该行
objExcel.Run "Data_Analysis"
和
objExcel.Run "sheet1.Data_Analysis"
跟进
试试这个代码。
Dim objExcel, objWorkbook, ad, FilePath
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
For Each ad In objExcel.AddIns
If ad.Name = "Converteam.xla" Then
FilePath = ad.Path & "\Converteam.xla"
Exit For
End If
Next
objExcel.Workbooks.Open (FilePath)
Set objWorkbook = objExcel.Workbooks.Open("C:\Folder\Test_PO.xls")
objExcel.Run "Data_Analysis_Converteam"
objWorkbook.Close
objExcel.Quit
Set objWorkbook = Nothing
Set objExcel = Nothing
WScript.Echo "Finished."
WScript.Quit
解释:
使用时CreateObject
,默认情况下不安装加载项。请看这个链接。
主题:在 Excel 中使用 CreateObject 命令时加载项不加载
链接: http: //support.microsoft.com/kb/213489/
您必须加载加载项,然后调用相关的宏。此外,您的宏的名称不是Data_Analysis
但是Data_Analysis_Converteam
高温高压