Option
Explicit
Private
Declare
Function
GetCommandLine
Lib
"kernel32.dll"
Alias
"GetCommandLineA"
()
As
Long
Private
Declare
Function
lstrlen
Lib
"kernel32.dll"
Alias
"lstrlenA"
( _
ByVal
lpString
As
Any)
As
Long
Private
Declare
Sub
CopyMemory
Lib
"kernel32.dll"
Alias
"RtlMoveMemory"
( _
ByRef
pDst
As
Any, _
ByRef
pSrc
As
Any, _
ByVal
ByteLen
As
Long
)
Private
Sub
Workbook_Open()
Dim
Args()
As
String
Args = getCommandLineArgs()
MsgBox Args(0)
End
Sub
Private
Function
getCommandLineArgs()
Dim
strCmdLine
As
String
, strArguments()
As
String
Dim
lngArgumentsCount
As
Long
Dim
lngReturn
As
Long
, lngLength
As
Long
Stop
lngReturn = GetCommandLine
lngLength = lstrlen(lngReturn)
If
CBool
(lngLength)
Then
strCmdLine = Space$(lngLength)
Call
CopyMemory(
ByVal
strCmdLine,
ByVal
lngReturn, lngLength)
End
If
strCmdLine = Left$(strCmdLine, InStr(strCmdLine & vbNullChar, vbNullChar) - 1)
If
CBool
(InStr(strCmdLine,
"/e"
))
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 <> vbNullString
strCmdLine = Mid$(strCmdLine, 2)
ReDim
Preserve
strArguments(lngArgumentsCount)
If
CBool
(InStr(strCmdLine,
"/"
))
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
getCommandLineArgs = strArguments
End
If
End
If
End
Function