AW: Konsolenparameter abfragen
20.05.2005 10:41:25
bst
Hallo Alex,
der Parameter muß vor den Dateinamen. Wie's mit Leerzeichen darin aussieht habe ich noch nicht probiert.
Zum Aufrufparameter, wenn Du sowas nimmst:
excel /e/4711 d:\daten\kommandozeile04.xls
ergibt's mit unterem Code "4711".
Übrigens, warum machst Du denn eigentlich nicht einfach sowas:
set myParam=schnickschnack
excel Meinedatei.xls
und liest in Excel die Umgebungsvariable myParam via Environ() aus ?
Ist sich IMHO viel einfacher ...
HTH, Bernd
--
Option Explicit
Private Sub Workbook_Open()
Call GetCmdLineParam
End Sub
--
Option Explicit
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" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Function GetCommLine() As String
Dim RetStr As Long, SLen As Long
Dim Buffer As String
'Get a pointer to a string, which contains the command line
RetStr = GetCommandLine
'Get the length of that string
SLen = lstrlen(RetStr)
If SLen > 0 Then
'Create a buffer
GetCommLine = Space$(SLen)
'Copy to the buffer
CopyMemory ByVal GetCommLine, ByVal RetStr, SLen
End If
End Function
Sub GetCmdLineParam()
Dim myParam As String
Dim i As Integer, j As Integer
myParam = GetCommLine
'Prüfen, ob "/e/" in der Befehlszeile enthalten ist
i = InStr(LCase(myParam), "/e/")
If i > 0 Then
myParam = Mid$(myParam, i + 3)
j = InStr(myParam, "/")
If j
If j > 0 Then myParam = Left(myParam, j - 1)
MsgBox "Aufrufparameter: " & myParam
Else
MsgBox "Die Kommandozeile ist: " & myParam
End If
End Sub