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!
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!