Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to determine if a particular worksheet (if any) is open in code?

Status
Not open for further replies.

groundclutter

Programmer
Apr 26, 2000
40
US
I must be having a brain-cramp because this shouldn't be difficult to do. But, I've been away from VBA for a while and can't seem to remember which object/property I should be evaluating to determine whether or not I should continue with the rest of my code.

Thanks!
 
Ok, after reading my initial post, I better provide some more detail...

The requestor has an Excel add-in that loads on startup with a custom menu bar and custom buttons. These buttons have macros assigned to them that apply to particular spreadsheets of data that are exported from Crystal Reports. The problem is right now that he would like a validation done that would occur when the button is first selected. The validation would make sure only that an active worksheet is open and that the active workbook is not empty.

A dialog box to prompt "are you sure you want to do this?" would be okay per the user but in my mind is kind of redundant.

Sorry for the multiple posts...
 
Lots of ways you could go here. Here's a sub that loops through all worksheets of all open books. It currently just prints their names to the Immediate window, but you could easily modify it to look for a specific workbook name, etc.:
Code:
Sub CheckForWorkbook()
Dim WB As Workbook
Dim WS As Worksheet

For Each WB In Workbooks
   Debug.Print WB.Name
   For Each WS In WB.Worksheets
      Debug.Print WS.Name
      ' Test each sheet for contents here
   Next WS
Next WB
End Sub
Keep in mind that add-ins are considered open workbooks, too. Let me know if you need more specific help on testing for contents on a sheet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top