![]() |
command line excel to run macros
"Anthony Ryan" wrote in message ... Try this, Create a batch file with this code: start excel "C:\Test.xls" /macro=mymacro or Win95 shortcut with this in the Target line: "C:\Test.xls" /macro=mymacro in the Test.xls spreadsheet in a module or the place where you wish to place your code In the declarations section place: Public Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineA" () As String Then create the subroutine called Auto_Open() or in the Workbook_Open() subroutine and place in it: Dim strCommand as String ' Get the commandline argument strCommand = GetCommandLine() ' Removes all text before mymacro strCommand = Right$(strCommand, Len(strCommand) - Instr(1, strCommand, "/macro=") - 7) ' Removes all text after mymacro strComannd = Left$(strCommand, Instr(1, strCommand, Chr$(0)) - 1) ' This statements run the macro defined by strCommand in the currently opened workbook Application.Run "'" & ThisWorkbook.Name & "'!" & strCommand I hope you suceed with this as my original code is a little different but I used this to control if a addin was to be loaded in or not. If the spreadsheet was opened by the batch file the commandline was present (the addin was loaded) and if it was opened in Windows Explorer by double-clicking it a commandline argument was NOT present (the addin was NOT loaded) Anthony "baldev" wrote in message ... does anyone know how to run excel from a command line incorporating Excel macro eg Call Excel.exe /macro=mymacro |
All times are GMT +1. The time now is 05:31 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com