Wait for External Application...

Local time
Today, 20:35
Joined
Aug 3, 2005
Messages
66
Hello,

While the form is open, the user can open an external application (eg. MSWord).

I want the form to "monitor" or "check" when the external application is CLOSED.

Only when the external application was open and have been closed, I want to display a Msgbox.

NOTE: the user does not run the external app from within the form (eg. cmdbutton). The external app is opened from the Start/Programs menu.

So basically I want my form to 'continuously' check if an external application (word.exe) is running(or not) and then display a msgbox when that app is closed.

Any ideas ?

Thank you.
 
Open a hidden form when the application opens.
In this hidden form:

- Set the Timer interval to 1000

- Set the On Open event to:
Code:
Private Sub Form_Open(Cancel As Integer)
    booWordOpen = False
End Sub

- Set the On Timer event to:
Code:
Private Sub Form_Timer()
    If FindWindow("OpusApp", vbNullString) > 0 Then 'OpusApp is MS Word's class name
        booWordOpen = True
    Else
        If booWordOpen = True Then 'Word was open, but now it's closed
            MsgBox "Word was closed."
            booWordOpen = False
        End If
    End If
    
End Sub

- Add these declarations at the top of the VBA file
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private booWordOpen As Boolean

Hope this helps, good luck :)
 
Compile Error

Thank you, but...

I did create a new Module with this in it :

_______________________

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private booIsAppRunning As Boolean
________________________

But on Debug/Compile, at the Form's OnTimer event, I get error "Sub or Function not defined".

I know it's something wrong on my side. Working on it....

Any help is appreciated.

Thanks again,
Jamie.
 
Sorry...

Forgive me....

I should have mentioned that I changed your "booWordOpen" to my "booIsAppRunning".

Still getting the Compile error though...

_____________________________________
Private Sub Form_Timer()

If FindWindow("MozillaUIWindowClass", vbNullString) > 0 Then 'OpusApp is MS Word's class name
booIsAppRunning = True
Else
If booIsAppRunning = True Then 'Word was open, but now it's closed
MsgBox "Word was closed."
booIsAppRunning = False
End If
End If
End Sub
______________________________________

Thanks.
 
This bit
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private booIsAppRunning As Boolean
goes in the same file as the code of your events. The "module" that comes with the form.

You could place it in a module but then you'd have to replace "Private" with "Public" on both lines.

Good luck!
 
Solved

Since I'm going to use the function on more than one form I created the new Module(public).

And i knew the 'Private' had to change to 'Public'. Just wasn't concentrating.
I Apologize.

All works great now.

Thank You for your help.

Regards,
Jamie.
 

Users who are viewing this thread

Back
Top Bottom