Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
m a m a is offline
external usenet poster
 
Posts: 1
Default why doesn't excel97 winNT vba macro code work in excel2002 winXP???

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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default why doesn't excel97 winNT vba macro code work in excel2002 winXP???


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


m a wrote:

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!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default why doesn't excel97 winNT vba macro code work in excel2002 winXP???

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


keepITcool wrote:


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


m a wrote:

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!




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default why doesn't excel97 winNT vba macro code work in excel2002 winXP???

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!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default why doesn't excel97 winNT vba macro code work in excel2002 winXP???

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!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
xyScatterChart macro works on WinXP Pro & not on WinXP Home? [email protected] Excel Discussion (Misc queries) 0 July 18th 05 12:30 AM
MS-Query code from EXCEL97 doesn't work in EXCEL2003 ?? ln54 Excel Discussion (Misc queries) 4 February 21st 05 08:12 PM
formula from Excel97 doesn't work in Excel2003,any ideas why? nic Excel Worksheet Functions 6 November 8th 04 04:40 PM
excel97: filtering out the zeros macro Joe[_21_] Excel Programming 2 June 16th 04 02:35 PM
Old button code not working in Excel2002 shanej Excel Programming 0 July 16th 03 02:10 AM


All times are GMT +1. The time now is 03:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"