Mit folgendem vbs Script kann ich problemlos Excedatei starten und ein bestimmtes Makro ausführen; fuktioniert auch über Task Scheduler.
VBS Script:
'Input Excel File's Full Path
ExcelFilePath = "c:\hs\test.xlsm"
'Input Module/Macro name within the Excel File
MacroPath = "Modul3.start"
'Create an instance of Excel
Set ExcelApp = CreateObject("Excel.Application")
'Do you want this Excel instance to be visible?
ExcelApp.Visible = True 'or "False"
'Prevent any App Launch Alerts (ie Update External Links)
ExcelApp.DisplayAlerts = False
'Open Excel File
Set wb = ExcelApp.Workbooks.Open(ExcelFilePath)
'Execute Macro Code
ExcelApp.Run MacroPath
'Save Excel File (if applicable)
wb.Save
'Reset Display Alerts Before Closing
ExcelApp.DisplayAlerts = True
'Close Excel File
wb.Close
'End instance of Excel
ExcelApp.Quit
VBA Code:
Private Declare PtrSafe Function w_commandline Lib "kernel32.dll" Alias "GetCommandLineW" () As LongPtr
Private Declare PtrSafe Function w_strlen Lib "kernel32.dll" Alias "lstrlenW" (ByVal lpString As LongPtr) As Long
Private Declare PtrSafe Sub w_memcpy Lib "kernel32.dll" Alias "RtlMoveMemory" (dst As Any, src As Any, ByVal size As LongPtr)
Public Function GetCommandLine() As String
GetCommandLine = String$(w_strlen(w_commandline()), 0)
w_memcpy ByVal StrPtr(GetCommandLine), ByVal w_commandline(), LenB(GetCommandLine)
End Function
Private Sub Workbook_Open()
gn_cmdline = GetCommandLine()
…
Ich möchte jedoch, daß kein bestimmtes Makro ausgeführt wird, sondern Workbook.open einen zu übergebenden Parameter auswerten (in gn_cmdline) kann, der im vbs beim Excelaufruf übergeben wird.
Irgendwie bekomme ich das aber nicht hin; hat jemand eine Idee?
Danke für Hilfe!
MfG
Heinz