Check Excel's state to see if a workbook is loaded in App

  • Thread starter Thread starter Chris w.
  • Start date Start date
C

Chris w.

Does anyone know if there is a way to check Excel App. to
see if there is actually a workbook open. I'm refferring
to the conditon where Excel is open but there is no
workbook open (loaded), I would like to cancel code from
running if the App. has no loaded workbook
 
How about:

If ActiveWorkbook Is Nothing Then
MsgBox "no active workbook"
Exit Sub
End If

At the top of your procedure.
 
Hi Chris,

It's not clear how you've opened or are controlling this
instance of Excel, but the following may help (It works as
a sheet event within a workbook in Excel):

Private Sub Worksheet_SelectionChange(ByVal Target As
Range)
MsgBox Application.Workbooks.Count
End Sub

App.Workbooks.Count may get you there.

Best Regards,
Walt
 

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

Back
Top