How to find out whether the current document is running in another application (such as Internet Explorer, Outlook, etc.)
Article contributed by Will Rickards and Dave Rado
When you open a Word document in another application, such as Internet Explorer, and then subsequently open Word in the normal way, you unfortunately don't get two separate instances of Word, you get one. If you have written event procedures, or intercepted Word commands, then depending on the circumstances, they may still run when you are in a document that is running inside another application. However, many VBA functions don't work in that scenario, and some actually crash Word. So you may sometimes need to allow, in your code, for the possibility that the active document might be running inside another application.
Two simple examples of VBA functions that won't work in this scenario are Application.Quit and ActiveDocument.Close, which both give the error “This method or property is not available because the document is in another application”.
You can test for this scenario using the following code:
If Documents.Count > 1
Then
If Len(ActiveWindow.Caption) = 0
Then
'The document
is running within another application
End If
End If
Unfortunately, it seems that you can't find out which application it is running in, because:
MsgBox ActiveDocument.Application.Name
... returns “Microsoft Word”. Confusing, huh!