AW: Aufruf Excel mit Parameter 2. Teil
28.08.2006 18:16:34
Nepumuk
2. Das herausfiltern der Argumente im Klassenmodul "DieseArbeitsmappe" der aufgerufenen Mappe:
Option Explicit
Private Declare Function GetCommandLine Lib "kernel32.dll" Alias "GetCommandLineA" () As String
Private Sub Workbook_Open()
Dim strCmdLine As String, strArguments() As String
Dim lngArgumentsCount As Long
strCmdLine = GetCommandLine()
strCmdLine = Left$(strCmdLine, InStr(strCmdLine & Chr$(0), Chr$(0)) - 1)
If InStr(strCmdLine, "/e") <> 0 Then
If Len(strCmdLine) - InStr(strCmdLine, "/e") > 1 Then
strCmdLine = Mid$(strCmdLine, InStr(strCmdLine, "/e") + 2)
strCmdLine = Left$(strCmdLine, InStr(strCmdLine, " ") - 1)
strCmdLine = Trim$(strCmdLine)
Do While strCmdLine <> ""
strCmdLine = Mid$(strCmdLine, 2)
ReDim Preserve strArguments(lngArgumentsCount)
If InStr(strCmdLine, "/") <> 0 Then
strArguments(lngArgumentsCount) = _
Left$(strCmdLine, InStr(strCmdLine, "/") - 1)
Else
strArguments(lngArgumentsCount) = strCmdLine
End If
strCmdLine = Right$(strCmdLine, Len(strCmdLine) - _
Len(strArguments(lngArgumentsCount)))
lngArgumentsCount = lngArgumentsCount + 1
Loop
If lngArgumentsCount = 2 Then
Application.Run strArguments(0), strArguments(1)
End If
End If
End If
End Sub