Is there a collection that holds all sheets: work- chart- dialog-

JohnKauffman

New Member
Joined
Nov 1, 2012
Messages
36
Is there a collection that holds all sheets: work- chart- dialog- ?
What would be the DIM datatype of a member? (none of the intellitype options seem to fit)
Also, when I add the use of the dialog() collection VBA says it can't recognize the whole sub()
Tester I am using

Sub CollectionsSheet()
' ? what collection holds all sheets: work-, chart- dialog-

Dim wsSheetCurrent As Worksheet
Dim wsChartCurrent As Chart
Dim dlgDialogCurrent As Dialog

For Each wsSheetCurrent In Worksheets()
MsgBox "Worksheet object in WorkSheets collection: " & Chr(13) & wsSheetCurrent.Name
Next wsSheetCurrent

For Each wsChartCurrent In Charts()
MsgBox "Chart object in Sheets collection: " & Chr(13) & wsChartCurrent.Name
Next wsChartCurrent

' ??? when using dialogs() VBA says entire sub() not recognized
'For Each dlgDialogCurrent In Dialogs()...
' MsgBox dlgDialogCurrent.Name
'Next dlgDialogCurrent
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Perhaps Sheets is the collection you want.
 
Upvote 0
Thanks Norie
Sheets() fails when enumerates to a chart sheet.
Perhaps wrong DIM data type for a member?

' fails when enumerates to first chart sheet
Dim wsSheetCurrent As Worksheet
For Each wsSheetCurrent In Sheets()
MsgBox "Worksheet object in Sheets collection: " & Chr(13) & wsSheetCurrent.Name
Next wsSheetCurrent
 
Upvote 0
As you are iterating thru the Sheets collection, you need a variable that can refer to all types of sheets. Hence, you can Dim sht As Object (or equivalent variable name):

Code:
Dim sht As Object
For Each sht In Sheets()
MsgBox "Sheet object in Sheets collection: " & Chr(13) & sht.Name
Next sht
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top