The answer is yes, using environment variables defined in the .bat file, which are read by the VBA Environ function in the workbook macro which is called from the .xls Workbook_Open event procedure.
However, a more flexible way is by using a VBScript file, for example Test.vbs:
Set objExcel = CreateObject("Excel.Application")
With objExcel
.Workbooks.Open "C:\Macros\My Macro 1.xls"
.Visible = True
.Run "The_Macro", 1, "ABC", Now-1, 99.99
.ActiveWorkbook.Close True
.Quit
End With
And in a standard module in My Macro 1.xls:
Public Sub The_Macro(Arg1 As Integer, Arg2 As String, Arg3 As Date, Optional Arg4 As Single = 0#)
MsgBox Now & vbNewLine & ActiveWorkbook.FullName & vbNewLine & _
"Arg1 (Integer) = " & Arg1 & vbNewLine & _
"Arg2 (String) = " & Arg2 & vbNewLine & _
"Arg3 (Date) = " & Arg3 & vbNewLine & _
"Arg4 (Single) = " & Arg4, Title:="Run by VBScript file"
End Sub
Bookmarks