Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
execute macro from command line
Hello,
I would like to run a macro in a workbook from the command line. The macro modifies the contents of the workbook. This is so I can automate a task rather than open the workbook, run macro, and save. Thanks! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
execute macro from command line
it's unusual to execute a vba macro from the command line.
how about coding windows shell program that automates the excel? shell programming uses vbscript(*.vbs) or javascript(*.js) if you're familiar with vba, you would not have difficulty with that. plz refer http://msdn2.microsoft.com/en-us/library/aa286544.aspx -- msn --------------------------------------------- the best time to plant a tree was twenty years ago. the second best time, is today - Chinese proverb "swansong" wrote: Hello, I would like to run a macro in a workbook from the command line. The macro modifies the contents of the workbook. This is so I can automate a task rather than open the workbook, run macro, and save. Thanks! |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
execute macro from command line
I'm not sure that you can do this directly but you can use a vbs file as an
intermediary and that might accomplish what you want. For the example, I have a macro named "macroA" that is in the workbook "C:\Test\Bookx.xls". I then use notepad to create a file named "C:\Test\LaunchMacro.vbs" (the vbs file would not have to be in the same folder, but you will need to know the path for your command line entry). The contents of LaunchMacro.vbs are shown between the lines below: ______________________________________ myMacro = WScript.Arguments.Item(0) Set objXL = CreateObject("Excel.Application") Set objWkbk = objXL.Workbooks.Open("C:\Test\Bookx.xls") objXL.Run myMacro objWkbk.Save objWkbk.Close objXL.Quit _________________________________________ Now, if I launch the vbs file and hand it the name of the macro as the argument, the workbook will open hidden, run the macro, save changes and close. The command line in this case would be: C:\Test\LaunchMacro.vbs "macroA" Steve "swansong" wrote in message ... Hello, I would like to run a macro in a workbook from the command line. The macro modifies the contents of the workbook. This is so I can automate a task rather than open the workbook, run macro, and save. Thanks! |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
execute macro from command line
Whilst I would consider the other replies better, you can start a new
instance of Excel, passing arguments, that are parsed by your WB. See the earlier thread in this NG "Reading command line parameters in a VBA program". NickHK "swansong" wrote in message ... Hello, I would like to run a macro in a workbook from the command line. The macro modifies the contents of the workbook. This is so I can automate a task rather than open the workbook, run macro, and save. Thanks! |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
execute macro from command line
Thanks!
Seems to work except the macro is not deleting worksheets. Is this because there is a prompt that asks if you really want to delete the worksheet? Any workaround to that? "Steve Yandl" wrote: I'm not sure that you can do this directly but you can use a vbs file as an intermediary and that might accomplish what you want. For the example, I have a macro named "macroA" that is in the workbook "C:\Test\Bookx.xls". I then use notepad to create a file named "C:\Test\LaunchMacro.vbs" (the vbs file would not have to be in the same folder, but you will need to know the path for your command line entry). The contents of LaunchMacro.vbs are shown between the lines below: ______________________________________ myMacro = WScript.Arguments.Item(0) Set objXL = CreateObject("Excel.Application") Set objWkbk = objXL.Workbooks.Open("C:\Test\Bookx.xls") objXL.Run myMacro objWkbk.Save objWkbk.Close objXL.Quit _________________________________________ Now, if I launch the vbs file and hand it the name of the macro as the argument, the workbook will open hidden, run the macro, save changes and close. The command line in this case would be: C:\Test\LaunchMacro.vbs "macroA" Steve "swansong" wrote in message ... Hello, I would like to run a macro in a workbook from the command line. The macro modifies the contents of the workbook. This is so I can automate a task rather than open the workbook, run macro, and save. Thanks! |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
execute macro from command line
Nevermind! I set
Application.DisplayAlerts = False At the start of the macro and set to true at the end. Working 100% "swansong" wrote: Thanks! Seems to work except the macro is not deleting worksheets. Is this because there is a prompt that asks if you really want to delete the worksheet? Any workaround to that? "Steve Yandl" wrote: I'm not sure that you can do this directly but you can use a vbs file as an intermediary and that might accomplish what you want. For the example, I have a macro named "macroA" that is in the workbook "C:\Test\Bookx.xls". I then use notepad to create a file named "C:\Test\LaunchMacro.vbs" (the vbs file would not have to be in the same folder, but you will need to know the path for your command line entry). The contents of LaunchMacro.vbs are shown between the lines below: ______________________________________ myMacro = WScript.Arguments.Item(0) Set objXL = CreateObject("Excel.Application") Set objWkbk = objXL.Workbooks.Open("C:\Test\Bookx.xls") objXL.Run myMacro objWkbk.Save objWkbk.Close objXL.Quit _________________________________________ Now, if I launch the vbs file and hand it the name of the macro as the argument, the workbook will open hidden, run the macro, save changes and close. The command line in this case would be: C:\Test\LaunchMacro.vbs "macroA" Steve "swansong" wrote in message ... Hello, I would like to run a macro in a workbook from the command line. The macro modifies the contents of the workbook. This is so I can automate a task rather than open the workbook, run macro, and save. Thanks! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Run macro from command line | Excel Programming | |||
Execute a macro from command line: possible or not ? | Excel Programming | |||
Macro won't execute from a Command Button | Excel Programming | |||
Creating command buttons beside every row to execute each row macro | Excel Programming | |||
Execute a command line app but i want a string returned. | Excel Programming |