I've written a bit of code that launches a document with the appropriate app, using ShellExecuteEx
However, I want the code to wait until the user is finished with the document, after which it will check the document for changes and respond accordingly. Should be easy, right?
The code below works fine for many documents. If I launch a JPG with it, for example, it happily launches the associated program. Sits there. When I close it, it comes back to my proggy and happy days.
Not so with Microsoft Word. It launches happily. Sits there. And then when I close it, it closes the document, tries to close the Word Application. And waits. And Waits. And WAAAAAAAIIIIIITTTTTSSSSS..
I checked, and when I go use a bit of code to iterates through all the processes to find the one associated with winword.exe, it finds one alright, but its pid is NOT the same as that returned in hProcess in SEI.
help me. For the love of Science!
BTW - I found a number of places on t' web where people said they had similar problems, but nobody posted a solution.
Public Function SyncShellDoc(ByVal PathName As String, _
ByVal WindowStyle As VbAppWinStyle) As Long
Dim lngPid As Long
Dim lngExitCode As Long
Dim SEI As SHELLEXECUTEINFO
SEI.cbSize = Len(SEI)
SEI.fMask = SEE_MASK_NOCLOSEPROCESS
SEI.hwnd = GetDesktopWindow
SEI.lpVerb = "open"
SEI.lpFile = PathName
SEI.lpDirectory = vbNullChar
SEI.lpParameters = vbNullChar
SEI.nShow = WindowStyle
lngPid = SEI.hProcess
If lngPid <> 0 Then
WaitForSingleObject lngPid, INFINITE
If GetExitCodeProcess(lngPid, lngExitCode) <> 0 Then
SyncShellDoc = lngExitCode
Err.Raise &H8004AA00, "SyncShell", _
"Failed to retrieve exit code, error " _
Err.Raise &H8004AA02, "SyncShell", _
"Failed to Shell child process"