I have an Excel VBA macro, its function is to compare two excels and build the comparison result in a new excel file. When running macro, a window will pop up and let me choose the files to compare.
Now I want to do this from the command line. I created a batch file with the following content:
Set MacroName=RoundTrip_VCRIComparison3
"C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE" "C:\2_workitems_exported_macro_20200319.xlsm"
And put this code to Excel VBA ThisWorkBook Object:
Private Sub Workbook_Open()
Dim strMacroName As String
strMacroName = CreateObject("WScript.Shell").Environment("process").Item("MacroName")
If strMacroName <> "" Then Run strMacroName
End Sub
But this can only open my excel and run macro, but it cannot specify files to compare. Does anyone know how to solve it?
Workbook_Openalready reads "MacroName" from an environmental variable. It can also read the names of the two files to be compared, and pass those names to the macro when you call it usingRun- Tim Williams