Private Declare PtrSafe Function GetCommandLine Lib "kernel32" Alias "GetCommandLineA" () As LongPtr
Private Declare PtrSafe Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As LongPtr) As Long
Private Declare PtrSafe Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As LongPtr) As Long
Private Function GetCmd() As String
Dim lpCmd As LongPtr
lpCmd = GetCommandLine()
GetCmd = Space$(lstrlen(ByVal lpCmd))
lstrcpy ByVal GetCmd, ByVal lpCmd
End Function
Private Sub Workbook_Open()
Dim macmdline As Variant
Dim monparam As Variant 'déclare une variable
Dim macmd As Variant 'déclare une variable
macmdline = GetCmd 'affecte la valeur de la ligne de commande
If Not IsNull(macmdline) Then 'si la variable est nulle
If Len(macmdline) > 0 Then 'on s'assure qu'il y a eu une ligne de commande passée
If InStr(macmdline, "/cmd") > 0 Then
macmdline = Replace(macmdline, ThisWorkbook.FullName, "", , , vbTextCompare)
monparam = Split(macmdline, "/cmd")
'MsgBox monparam(1)
macmd = Split(monparam(1), " ")
'MsgBox "0=>" & macmd(0) & "<="
Application.Run Mid(macmd(0), 2)
End If
End If
End If
End Sub
Partager