Master Work
asked on
I need to run maco in Excel using command line or VBS.
I need to run maco in Excel using command line or VBS. Please find attached the excel file with the maco and the vbs I created but it was not working.
Regards,
Dallag
Regards,
Dallag
'Create an instance of Excel
Set xlsApp = CreateObject("Excel.Application")
'Remove the following line to open Excel in the background
xlsApp.Visible = true
'Open your file
Set xlsWB = xlsApp.Workbooks.Open("D:\0 Aramco\0 Prpjects\0 UR\NA\System-A-B1-new-format_test_v3.xlsm")
'You can call macros connected to sheets or the workbook
Set xlsSheet = xlsWB.Worksheets(1)
'Call xlsWB.MakeFinal() 'To call a macro in ThisWorkbook
'Call xlsSheet.macroname() 'To call a macro in Sheet1
'False here just makes it not prompt to save
xlsWB.Close(False)
xlsApp.Quit
new-format_test_v3.xlsm
ASKER
I have many macros and I need to select.
The basic concept is
Dim xlApp
Dim xlBook
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\MyWorkbook.xls")
xlApp.Run "YourMacroNameToBeRun"
xlApp.Quit
Set xlBook = Nothing
Set xlBook = Nothing
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much
Then launch excel from the command line or script and have it open that book:
excel /t <filename>