For each on shapes, avoiding ActiveX controls

spacebouncer

Board Regular
Joined
Feb 7, 2014
Messages
109
I have some code that runs for each shape on a sheet. The code starts with a conditional, checking the name and title of the shape.

The code fails if I have ActiveX objects on the sheet. I'm thinking I could get over this with "On Error..." but I'd rather have use an IF statement and Exit For if its the wrong type. Don't really know the best way to do this.

Advice much appreciated. Thanks
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try...

Code:
    [COLOR=darkblue]Dim[/COLOR] Shp [COLOR=darkblue]As[/COLOR] Shape
    
    [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] Shp [COLOR=darkblue]In[/COLOR] ActiveSheet.Shapes
        [COLOR=darkblue]If[/COLOR] Shp.Type <> msoOLEControlObject [COLOR=darkblue]Then[/COLOR]
            [COLOR=green]'etc...[/COLOR]
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    [COLOR=darkblue]Next[/COLOR] Shp

Also, one can loop through specific shapes and form controls. Here are a couple of examples...

Code:
Oval shapes:

    [COLOR=darkblue]Dim[/COLOR] oOval [COLOR=darkblue]As[/COLOR] Oval
    
    [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] oOval [COLOR=darkblue]In[/COLOR] ActiveSheet.Ovals
        MsgBox oOval.Name
    [COLOR=darkblue]Next[/COLOR] oOval

Code:
Form control checkboxes:

    [COLOR=darkblue]Dim[/COLOR] oCheckBox [COLOR=darkblue]As[/COLOR] CheckBox
    
    [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] oCheckBox [COLOR=darkblue]In[/COLOR] ActiveSheet.CheckBoxes
        MsgBox oCheckBox.Name
    [COLOR=darkblue]Next[/COLOR] oCheckBox

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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