ist es möglich beim Aufruf vom Excel einen Parameter mitzugeben, den ich dann durch VBA auswerten kann.
z.B. test.xls hallo
dann könnte ich in dem Workbook_Open abfragen, wenn hallo dann dies, sonst jenes.
Danke für euer Hilfe
Steffen
"C:\Programme\Microsoft Office\Office\EXCEL.EXE" /e/Para1/Para2 "C:\Daten\Datei.xls"
Wichtig ist die Reihenfolge: die Parameter mit /e vor der zu öffnenden Datei.
Mit folgender Auto_Open in Datei.xls werden die Parameter angezeigt:
Option Explicit
Private Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineA" () As String
Sub Auto_open()
Dim CmdLine As String 'command-line string
Dim Args() As String 'array for storing the parameters
Dim ArgCount As Integer 'number of parameters
Dim Pos1 As Integer, Pos2 As Integer
CmdLine = GetCommandLine() 'get the cmd-line string
CmdLine = Left$(CmdLine, InStr(CmdLine & vbNullChar, vbNullChar) - 1)
On Error Resume Next 'for the wksht-function "Search"
Pos1 = WorksheetFunction.Search("/", CmdLine, 1) + 1 'search "/e"
Pos1 = WorksheetFunction.Search("/", CmdLine, Pos1) + 1 '1st param
If InStr(Pos1, CmdLine, " ") > 0 Then CmdLine = Left$(CmdLine, InStr(Pos1, CmdLine, " "))
Do While Err = 0
Pos2 = WorksheetFunction.Search("/", CmdLine, Pos1)
ArgCount = ArgCount + 1
ReDim Preserve Args(ArgCount)
Args(ArgCount) = Mid(CmdLine, Pos1, _
IIf(Err, Len(CmdLine), Pos2) - Pos1)
MsgBox "Argument " & ArgCount & " : " & Args(ArgCount)
Pos1 = Pos2 + 1
Loop
End Sub
Gruß