I needed a vbs script that opens a .xlsm file, runs a macro in it and closes the file again.
Online I found a script that works perfectly. Trouble is, I don't understand how.
This is the script :
Sub MacroExcel()
Dim ExcelApp
Dim ExcelFile
Set ExcelApp = CreateObject("Excel.Application")
Set ExcelFile = ExcelApp.Workbooks.Open("D:\File1.xlsm")
ExcelApp.Visible = True
ExcelApp.Run "Macro1"
ExcelApp.Quit
Set ExcelFile = Nothing
Set ExcelApp = Nothing
End Sub
How does this open the file in the first place? As I understand, this line :
Set ExcelFile = ExcelApp.Workbooks.Open("D:\File1.xlsm")
assigns a method to the variable ExcelFile. But then, ExcelFile is not used in the code anymore.
How does the script know that the file should actually be opened ?