ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Check if workbook is already open... (https://www.excelbanter.com/excel-programming/371077-check-if-workbook-already-open.html)

Cumberland[_9_]

Check if workbook is already open...
 

Is there a VBA command to check if a workbook is already open? I want to
be able to see if the workbook is already open before even attempting to
open it. Basically, I want the system to wait 5 seconds and then
re-check. If file is open, wait 5 seconds and retry. If not open, then
open it. The file in question is literally opened, an entry added, then
saved and closed, all in a macro. It is a quick operation, but
nonetheless I need to ensure that no one else can open the file, even
in read-only mode, even if there is only a very remote chance that they
could.

Thanks in anticipation.


--
Cumberland
------------------------------------------------------------------------
Cumberland's Profile: http://www.excelforum.com/member.php...o&userid=33445
View this thread: http://www.excelforum.com/showthread...hreadid=574066


Tim Marsh

Check if workbook is already open...
 
the following way worked for me, but i'm sure there must be a better
solution: -

'=====
Sub test()

On Error GoTo errmsg
Workbooks("Test.xls").Activate

errmsg:
MsgBox "that file is not open"

End Sub
'=====

hth,

tim

"Cumberland" wrote
in message ...

Is there a VBA command to check if a workbook is already open? I want to
be able to see if the workbook is already open before even attempting to
open it. Basically, I want the system to wait 5 seconds and then
re-check. If file is open, wait 5 seconds and retry. If not open, then
open it. The file in question is literally opened, an entry added, then
saved and closed, all in a macro. It is a quick operation, but
nonetheless I need to ensure that no one else can open the file, even
in read-only mode, even if there is only a very remote chance that they
could.

Thanks in anticipation.


--
Cumberland
------------------------------------------------------------------------
Cumberland's Profile:
http://www.excelforum.com/member.php...o&userid=33445
View this thread: http://www.excelforum.com/showthread...hreadid=574066





All times are GMT +1. The time now is 01:22 AM.

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