Hi Steve
You this code to get the command line that Word was started with. Then just parse out the
command line.
Public Declare Function GetCommandLine Lib "kernel32" _
Alias "GetCommandLineA" () As Long
Public Declare Function lstrlen Lib "kernel32" Alias _
"lstrlenA" (ByVal lpString As Long) As Long
Public Declare Function lstrcpy Lib "kernel32" _
Alias "lstrcpyA" (ByVal lpStringTo As String, _
ByVal lpStringFrom As Long) As Long
Public Sub ShowCommandLine()
MsgBox Trim$(StringFormPointer(GetCommandLine()))
End Sub
Public Function StringFormPointer(ByVal lngStrPointer As Long) As String
Dim lngCmdLength As Long
Dim strOut As String
' Get the length of the string the pointer points to
lngCmdLength = lstrlen(lngStrPointer)
' Preallocated the correct size buffer. add 1 as the string is null terminated
strOut = Space$(lngCmdLength + 1)
' Copy string to VBA buffer
lstrcpy strOut, lngStrPointer
' Trim off the null character that terminates the string
StringFormPointer = TrimN(strOut)
End Function
Function TrimN(ByVal strValue As String) As String
Dim lngPos As Long
lngPos = InStr(strValue, vbNullChar)
If lngPos > 0 Then
' Return everthing before the null character
TrimN = Left$(strValue, lngPos - 1)
Else
' Not found, so just return the original value.
TrimN = strValue
End If
End Function
HTH + Cheers - Peter