I need to write code that checks for the worksheet in all the open workbooks.
Reason is, I made some toolbars that are only used for my program. When you close the program I have it delete the toolbars. Problem is, if two copies of the program are open, and I delete the toolbar, then the 2nd one can’t use it. So I need to see if there are two copies open, and only delete the toolbars when BOTH are closed.
Just a suggestion, rather than going this route, you could add some code to add some text to your toolbar name that would correspond to the number of open programs. ex(TOOLBARNAME. for 1 open program, TOOLBARNAME… for two open programs) Then just do some IF…THEN when closing to adjust the name and close the toolbar if needed. OR, I know you can use the Window() function to move about and open/close worksheets, If you through in an ON LOCAL ERROR routine, you could trap out any non occurrence in the active workbook. I’m not sure how to determine the names of other open workbooks though, so I can’t help with that.
Try this:
Edit…just re read what you want, try this one.
numopen = Workbooks.Count
For i = 1 To numopen
If Workbooks.Item(i).Name = "WHATEVER" Then
numopenws = Workbooks.Item(i).Worksheets.Count
For j = 1 To numopenws
If Workbooks.Item(i).Worksheets.Item(j).Name = "WHATEVER" Then
'
'YOUR COMMANDS HERE
'
End If
Next j
End If
Next i