Detecting a another workbook has opended

N

Nigel

Hi All
In an Excel workbook is there a method to detect that the user has opended
or is opening another workbook ?

For instance......

A workbook application is open, the user navigates in explorer to another
xls file and double clicks it, this opens in the existing instance of xL, is
there a way for the already open workbook to detect this new workbook, with
the following actions....

1. Tell the user they must close the current application before loading a
new workbook
2. Prevent the new workbook from opening.
 
N

Nigel

In reply to my own request I have come up with the following approach, but
not sure if it is foolproof? Perhaps someone might comment on it?

Option Explicit
Public wbOpen As Boolean

Private Sub Workbook_Deactivate()
If Workbooks.Count > 1 And wbOpen Then
MsgBox "You must close MyApplication before opening another workbook"
'close the rogue book
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
End If
End Sub

Private Sub Workbook_Open()
wbOpen = True
If Workbooks.Count > 1 Then
MsgBox "OPEN - You must close the current Excel workooks before opening
MyApplication"
wbOpen = False
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top