try it
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
EDIT
If the macro is in the module, then this will help. If the macro is in a sheet, say Sheet1 then replace the line
objExcel.Run "Data_Analysis"
from
objExcel.Run "sheet1.Data_Analysis"
Followup
Try this code.
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
EXPLANATION
When you use CreateObject
, add-ins are not installed by default. See this link.
Subject: add-ins do not load when using CreateObject command in Excel
Link : http://support.microsoft.com/kb/213489/
You need to load the add-in, and then call the corresponding macro. Also, your macro name is not Data_Analysis
, but Data_Analysis_Converteam
NTN
source share