Check if workbook is already open...

C

Cumberland

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.
 
T

Tim Marsh

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
 

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