getcommandline problem

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
 
G

Guest

At least I'm not the only person who have problems with GetCommandLineA. I tried a lot and ended up with this little macro

Declare Function GetCommandLineA Lib "Kernel32" () As Strin

Sub probe(
Dim s As Strin
s = GetCommandLine
End Su

If I try to run this within Excel, Access or PowerPoint, I get a 'could not read memory' error message and the program crashes. But within Word it works perfectly well. And to carry this to extremes I've written an complex Excel program some month ago that uses the function GetCommandLineA and works (at least until I try to save it)

I hope someone can explain this behaviour, or at leat know a way get the macro running.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top