M
m a
hello everyone
I want launch a template that has a auto_open macro that
should read the command line and get the file name used by
another macro.
When I use the getcommandlineA function as follows:
*******
Option Base 1
Declare Function GetCommandLineA Lib "Kernel32" () 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 = GetCommandLineA 'get the cmd-line string
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
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
*******
the excel crashes.
Any ideas why this doesn't work???
Any help will be much appreciated.
thanks in advance
regards
MA
I want launch a template that has a auto_open macro that
should read the command line and get the file name used by
another macro.
When I use the getcommandlineA function as follows:
*******
Option Base 1
Declare Function GetCommandLineA Lib "Kernel32" () 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 = GetCommandLineA 'get the cmd-line string
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
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
*******
the excel crashes.
Any ideas why this doesn't work???
Any help will be much appreciated.
thanks in advance
regards
MA