Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() "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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to use Windows command within Excel macros | Excel Discussion (Misc queries) | |||
Are there command line parameters for Excel? | Excel Discussion (Misc queries) | |||
What are the possible command-line arguments in Excel? | Excel Discussion (Misc queries) | |||
command line Excel Script | Excel Discussion (Misc queries) | |||
macros from command line | Excel Discussion (Misc queries) |