ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Detecting a another workbook has opended (https://www.excelbanter.com/excel-programming/328922-detecting-another-workbook-has-opended.html)

Nigel

Detecting a another workbook has opended
 
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.


--
Cheers
Nigel





Nigel

Detecting a another workbook has opended
 
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


--
Cheers
Nigel



"Nigel" wrote in message
...
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.


--
Cheers
Nigel








All times are GMT +1. The time now is 10:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com