I want to run a test when the workbook opens to make sure the vital sheets are present before any more events happen. The For Each loop I am using seems to work everywhere else except in the Workbook_Open() section. Here is the code I am using. The bln---'s are used to check off if each sheet is present.
Runtime error '13'
Type mismatch
In another part of the project, I use the same loop to add worksheets into a combobox, which works perfectly:
-JTBorton
Another Day, Another Disaster
Runtime error '13'
Type mismatch
Code:
Private Sub Workbook_Open()
Dim wkSht As Excel.Worksheets, blnListedCities As Boolean, blnMyMailingLists As Boolean, blnMainMenu As Boolean, _
blnContactManager As Boolean, blnAgendaManager As Boolean, blnAILManager As Boolean
[highlight]For Each wkSht In Worksheets[/highlight] [COLOR=green]'Make sure critical worksheets are in the workbook[/color]
Select Case wkSht.Name
Case "Main Menu"
blnMainMenu = True
Case "Listed Cities"
blnListedCities = True
Case "Contact Manager"
blnContactManager = True
Case "AILManager"
blnAILManager = True
Case "AgendaManager"
blnAgendaManager = True
Case "My Mailing Lists"
blnMyMailingLists = True
End Select
Next wkSht
End Sub
In another part of the project, I use the same loop to add worksheets into a combobox, which works perfectly:
Code:
Dim wkSht As Excel.Worksheet, objList As ComboBox
Set objList = cboViewAIL
objList.Clear
For Each wkSht In Worksheets
If LCase(Left(wkSht.Name, 3)) = "ail" And Not LCase(wkSht.Name) = "ail manager" Then
objList.AddItem Mid(wkSht.Name, 4, Len(wkSht.Name) - 3)
End If
Next wkSht
.
.
.
-JTBorton
Another Day, Another Disaster