I wrote Excel VBA to check whether any instance of Word is already running, but some problems are occurring.
- If I open the Word without opening a document, the line
If Err.Number = 0 Then wdAppRunning = True
returnsFalse
.
Open Word via Windows Start
The opened Word instance.
- If there is an instance of Word running on a background process, the line also returns
False
. - If I open Word, and create or open a document, and then run the macro, it returns the expected result (
True
)
How can I manage the code to identify at least the situation n° 1?
Ps.: the code posted in the link Getting instances of Word and saving documents returns the same situation.
Sub wdAppRunning()
Dim wdApp As Object
Dim wdAppRunning As Boolean
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number = 0 Then wdAppRunning = True
MsgBox wdAppRunning
Set wdApp = Nothing
End Sub