VBA : Hide & Show shape button that contain their own sub-shapes upon clicked

andersen_yunan

New Member
Joined
Feb 7, 2018
Messages
36
Hi, I happened to stuck with one problem for my project. Basically what I'm trying to do is hide and show shapes containing macro. To illustrate, so each shapes has their own set of sub-shapes (let's say there are 3 shapes with each has their own 2 sub-shapes). What i have in mind is that each time I click on one shape, the 2 sub-shapes would appear and if I clicked on other shapes, the previous 2 sub-shapes would hide themselves and let the other set of shapes appear.

I got the basic script for hide and show but couldn't find way to figure it out

Hide/Show script:
ActiveSheet.Shapes("Button 2").Visible = False
or
ActiveSheet.Shapes("Button 2").Enabled = False


Is there a better way to solve this problem?
Thank you in advance!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Try this, alter shapes to suit.
Code:
[COLOR=navy]Sub[/COLOR] Rectangle1_Click()
Hide
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]

[COLOR=navy]Sub[/COLOR] Oval3_Click()
Hide
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
[COLOR=navy]
Sub[/COLOR] IsoscelesTriangle2_Click()
Hide
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
[COLOR=navy]
Sub[/COLOR] Hide()
[COLOR=navy]Dim[/COLOR] Shp [COLOR=navy]As[/COLOR] Shape
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Shp [COLOR=navy]In[/COLOR] ActiveSheet.Shapes
    [COLOR=navy]If[/COLOR] Not Shp.Name = Application.Caller [COLOR=navy]Then[/COLOR]
        [COLOR=navy]With[/COLOR] Shp
            .Visible = Not .Visible
        [COLOR=navy]End[/COLOR] With
    [COLOR=navy]End[/COLOR] If
[COLOR=navy]Next[/COLOR] Shp
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0

Forum statistics

Threads
1,225,738
Messages
6,186,728
Members
453,368
Latest member
positivemind

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