Loop help

arage

Registered User.
Local time
Today, 20:45
Joined
Dec 30, 2000
Messages
537
Loop help
I’m running a FOR EACH NEXT loop that examines the controls in my command bar but it fails with a type mismatch because the last one examined has been disabled and I am having difficulty thinking how I can get out of this.

Here is the code.

For Each ctl In CommandBars("Filter Toolbar").Controls
If ctl.Text <> "" And ctl.Type = msoControlComboBox Then
i = i + 1
End If
Next
 
Have you Tried

Code:
For Each ctl In CommandBars("Filter Toolbar").Controls 
   If ctl.Enabled=True Then
     If ctl.Text <> "" And ctl.Type = msoControlComboBox Then 
         i = i + 1 
     End If 
   End If
Next
 
how do you manage to format your code?

how do you manage to format your code like that?
 
No that doesn’t work, same problem it hangs on the NEXT statement when it tries to go to the last control.
 
It just "HANGS" on the Next Statement? Have you just stepped through the code using the Debug BreakPoint?

As for how I formated the code, I used these wonderful tags that are now included in this forum. The Code is similar to the Bold/Italic/Underline. You just start your code with "[ Code ]" and end it with "[ /Code ]".

Note: Take out the spaces between the [].
 

Users who are viewing this thread

Back
Top Bottom