Make sure a worksheet is open

  • Thread starter Zanyar.Sigarchy
  • Start date
Z

Zanyar.Sigarchy

I am creating a macro that needs a worksheet to be open in order to
work, therefore I need to make sure that there is at least one
worksheet open otherwise my code crashes.

Here is how I am checking now, but this gives an error:

If Worksheets.Count < 1 Then
MsgBox gsERR_FILE_NOT_FOUND, vbCritical
CloseMyMacro
End If
 
K

Karl E. Peterson

I am creating a macro that needs a worksheet to be open in order to
work, therefore I need to make sure that there is at least one
worksheet open otherwise my code crashes.

Here is how I am checking now, but this gives an error:

If Worksheets.Count < 1 Then
MsgBox gsERR_FILE_NOT_FOUND, vbCritical
CloseMyMacro
End If

I've used this, with some success:

If Not ActiveWindow Is Nothing Then
 

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