Foo_Man_Chu
Board Regular
- Joined
- Jul 22, 2010
- Messages
- 79
I'm opening a spreadsheet two different ways: first by clicking on the icon for the spreadsheet and second via the command line so I can use command line arguments. My problem is this: when i open it via the command line it works as expected. When I open it by clicking on the icon it opens as if it has the command line passed in to it. How can i "flush" the command line parameter after it opens so that if I want to open it via clicking the icon and thus not wanting to have it run as if the command line argument was passed to it?
Here is my code:
Here is my code:
Code:
Option Base 0
Option Explicit
'api call for obtaining the username
Private Declare Function GetUserName& Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long)
Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineW" () As Long
Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (MyDest As Any, MySource As Any, ByVal MySize As Long)
Function CmdToSTr(Cmd As Long) As String
Dim Buffer() As Byte
Dim StrLen As Long
If Cmd Then
StrLen = lstrlenW(Cmd) * 2
If StrLen Then
ReDim Buffer(0 To (StrLen - 1)) As Byte
CopyMemory Buffer(0), ByVal Cmd, StrLen
CmdToSTr = Buffer
End If
End If
End Function
Public Sub Auto_Open()
Dim CmdRaw As Long
Dim CmdLine As String
Dim myParam As String
CmdRaw = GetCommandLine
CmdLine = CmdToSTr(CmdRaw)
myParam = Right(CmdLine, 4)
If myParam = "AUTO" Then
...........