why doesn't excel97 winNT vba macro code work in excel2002 winXP???

M

m a

I have the following macro code that works fine in excel97 winNT but not
in excel2002 winXP:

Private Declare Function GetCommandLine Lib "kernel32" _
Alias "GetCommandLineA" () As Long

Private Declare Function lstrlen Lib "kernel32" _
Alias "lstrlenA" _
(ByVal lpString As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(Destination As Any, _
Source As Any, _
ByVal Length As Long)
Global file_name As String

Public Function CommandEx() As String
Dim lpCmdLine As Long
Dim lLen As Long
'Get pointer to command line ansi string:
lpCmdLine = GetCommandLine()
If lpCmdLine Then
'Get length of ansi string:
lLen = lstrlen(lpCmdLine)
'Allocate space for copy:
CommandEx = String$(lLen, vbNullChar)
'Copy the string into our local String:
CopyMemory ByVal StrPtr(CommandEx), ByVal lpCmdLine, lLen
'Convert to Unicode and trim:
CommandEx = Left$(StrConv(CommandEx, vbUnicode), lLen)
End If
End Function

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
Dim Pos2 As Integer
CmdLine = CommandEx() '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)
file_name = Args(ArgCount)
Pos1 = Pos2 + 1
Loop
Call mppt_macro(file_name)
End Sub

This macro should read the commandline and return the file name to be
used for plotting a graph.

The command line is as follows:

excel /r c:\temp\template.xlt /e/c:\temp\data.xls

the file_name returned to the calling macro should be c:\temp\data.xls

In excel97 winNT it runs thru and loads in the data.xls and plots a
graph without any problem.

In excel2002 winXP excel starts and opens the template.xlt and does not
do anything further.

why???

I have found by looking at the watches that the variable lLen in the
Function CommandEx() contains less characters ie 67 as opposed to 97 or
something similar because the commandline is something like 97
characters long.

please help/advise and thanx in advance for your cooperation.


ma

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
K

keepITcool

I did reply on an earlier thread..

NOTE YOUR DECLARATION RETURNS A LONG POINTER!!

using ApiViewer2002 i get this:

Declare Function GetCommandLine Lib "kernel32" _
Alias "GetCommandLineA" () As String


api functions return strings which are terminated bij chr(0)


dim s$
s=getcommandline
msgbox left(s,instr(s,chr(0))-1)

works for me


keepITcool

< email : keepitcool chello nl (with @ and .) >
< homepage: http://members.chello.nl/keepitcool >
 
K

keepITcool

assuming you're developing for xl2000+ this would be an easier way to
parse the commandline

dim s$,v
s=getcommandline
s=left(s,instr(s,chr(0))-1)
v=split(v," /")

vargs is now a 0based array containing the arguments
v(0) is the call to excel which you can ignore
v(1) to ubound(v) contains your parameters

also you could use vba's INSTR function iso worksheetfunction.search



keepITcool

< email : keepitcool chello nl (with @ and .) >
< homepage: http://members.chello.nl/keepitcool >
 
T

the man in the know how

daclaration as string does not work.

I get type mismatch errors and when I sort the type errors then the line
where lLen is calculated excel comes up with error report to be sent to
microsoft and closes the application.

May I respectfully ask that the whole question/problem be read as I may
have missed something in the explanation.

Any further suggestions will be much appreciated.

regards

ma

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
T

the man in the know how

ta very much keepITcool

I'll try your suggestions.

much appreciative

ma

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 

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