Excel macro command for mac

broken image
broken image
broken image

If there is a macro name passed in proper format, execute the same using Run command. Here, we used the ‘/a’ parameter as a divider. Handle the command line arguments inside the Workbook_Open() method, which will get executed when the excel opens the workbook.Įxtract the command line with the help of the above module and get the macro name using the divider defined in the BAT file. Public Function CmdToStr(Cmd As Long) As String ‘Convert the command line from number format to string format ‘RtlMoveMemory will copy the specified data to the bufferĭeclare Sub CopyMemory Lib “kernel32” Alias “RtlMoveMemory” (MyDest As Any, MySource As Any, ByVal MySize As Long) ‘This function is for getting the length of the commandline argumentsĭeclare Function lstrlenW Lib “kernel32” (ByVal lpString As Long) As Long ‘GetCommandLineW returns the command line argument in number formatĭeclare Function GetCommandLine Lib “kernel32” Alias “GetCommandLineW” () As Long ‘ declare the kernel32 functions to extract the commandline arguments Insert the following code snippet inside the module. Open the excel workbook and navigate to the Visual Basic editor. We have achieved the objective using following code snippet. Recently we have got a requirement for executing a macro from command line.