How to tell if word is already running

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I tell if an instance of Word is already running from Access so that
I can issue a message to the user to close Word before they run my report?

Thanks
Jerry
 
JWS315 said:
How can I tell if an instance of Word is already running from Access
so that I can issue a message to the user to close Word before they
run my report?

One way is described at this link:

http://www.mvps.org/access/api/api0007.htm
API: Find out if an application is currently running

Another way would be to try to get a reference to the Word application
object, and see if you succeed:

Dim oWord As Object

On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Err.Number = 0 Then
Set oWord = Nothing
MsgBox "Word is running; please close it."
End If
 
Dirk - Thanks!

One additional question, If I find it is running can I issue a quit command
(oWord.Quit) to close the running instance before continuing my code? Will
this allow the user to either save the current document or will it just close
Word without offering a save as dialog?

TFH! - Jerry
 
JWS315 said:
Dirk - Thanks!

One additional question, If I find it is running can I issue a quit
command (oWord.Quit) to close the running instance before continuing
my code? Will this allow the user to either save the current
document or will it just close Word without offering a save as dialog?

I just tested it with the following code:

Dim oWord As Object

On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Err.Number = 0 Then
oWord.Activate
oWord.Quit
Set oWord = Nothing
End If

Word prompted me to save the document. However, the dialog box also
allowed me to Cancel the save, so you may need to program around that.
 
Back
Top