Check if Any workbooks are open

K

Kevin R

How do I check to see if ANY workbooks are open before running a macro? I
know how to check to see a particular workbook is open but I just want to
check to see if a (no specific) workbook is open before continuing the macro,
otherwise display a message if no workbook is open.
 
B

Bob Phillips

There must be at least one workbook open, the one with the code.

If Application.Workbooks.Count > 1 Then
...

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
J

Jim Thomlinson

You can count the number of open workbooks
MsgBox Application.Workbooks.Count
Note that personal.xls is a workbook which (if it exists) is hidden. You did
not specify how you wanted to handle that (if at all) so I will leave that up
to you...
 
D

Dave Peterson

Maybe you can just check for an active workbook?

Option Explicit
Sub testme()
If ActiveWorkbook Is Nothing Then
MsgBox "no visible workbook"
Else
MsgBox ActiveWorkbook.Name & " is active!"
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