Hi All,

I have a microsoft word document, and I have got class to handle the manipulation within those documents (I call it "Word").


My code goes this way:

-------------------------------
sub form load
set W = New Word ' W is the Word object
if usingW = true then
'open document in here
'manipulate it
'let the user evaluate it, user can close it anytime they want
end if
end sub

sub form unload
W.Quit ' There is a Quit sub in Word class, which basically erase the winword.exe
end sub

-------------------------------


If I am not using W at all, the winword.exe process can be closed properly when the form unloaded.

the problem exists when the user using the W:

First, if the user still open the word document (opened by the program), the user is forced to close it when the form unloaded.
How can I avoid this? I want to give the user flexibility to close the document whenever they want, even after the form unloaded. I want the program to know that those word documents are still opened, so it doesn't need to call W.Quit

Second, if the user has closed the word document (opened by the program), the program will produce run time error "the remote server machine does not exist or is unavailable"
How can I avoid this? I want the program to know that those word documents have been closed, so it doesn't need to call W.Quit

thanks

It all depends on what code you are using in your Quit function. Please post the code for that function and lets see where your problem arises.

When the document is closed and an error is raised, where in your code is the error generated. Show us that as well.

Andre, the line that generates the error is in the form unload event (w.quit)...

Okay neosonic, lets take this one at a time...

>First, if the user still open the word document (opened by the program), the user is forced to close it when the form unloaded. How can I avoid this?

Hide your form, use a timer with an interval set to at least 1000 (1 second) and use the FindWindow API to check to see if the specific word application you opened is still opened. If not, unload your form to end your program, else, continue to wait.

>I want to give the user flexibility to close the document whenever they want, even after the form unloaded. I want the program to know that those word documents are still opened, so it doesn't need to call W.Quit

Prompt the user with a message box...

>Second, if the user has closed the word document (opened by the program), the program will produce run time error "the remote server machine does not exist or is unavailable" How can I avoid this? I want the program to know that those word documents have been closed, so it doesn't need to call W.Quit

Two ways, trap the error and ignore it or use the FindWindow API...

Good Luck

This question has already been answered. Start a new discussion instead.