Problem with hiding a form control check box using code

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Problem with hiding a form control check box using code

Post by ABabeNChrist »

I’m having a problem with hiding a Form control check box using code
I have tried, with no success.

Code: Select all

Sheets("Structure and Exterior").Shapes("Check Box 29").Visible = False

Code: Select all

ActiveSheet.Shapes("Check Box 29").Visible = False
Now I am wondering if this could be my problem.
Within the same workbook I copied a worksheet named Grounds along with all of its controls, and named it Structure and Exterior. So now I have 2 identical sheets with only different names. So obviously all the form control check boxes have the same #.
I can use this code on the Grounds sheet and it will hide no problem

Code: Select all

Sheets("Grounds").Shapes("Check Box 29").Visible = False
Also here is my error message I receive
Error Message.JPG
You do not have the required permissions to view the files attached to this post.

User avatar
Jan Karel Pieterse
Microsoft MVP
Posts: 656
Joined: 24 Jan 2010, 17:51
Status: Microsoft MVP
Location: Weert, The Netherlands

Re: Problem with hiding a form control check box using code

Post by Jan Karel Pieterse »

Form controls are hidden members in the object list, you address them like so:

ActiveSheet.CheckBoxes("Check Box 1").Visible = True
Regards,

Jan Karel Pieterse
Excel MVP jkp-ads.com

User avatar
rory
5StarLounger
Posts: 817
Joined: 24 Jan 2010, 15:56

Re: Problem with hiding a form control check box using code

Post by rory »

I suspect the names are wrong. What appears in the Name box if you right-click the control?
Regards,
Rory

User avatar
sdckapr
3StarLounger
Posts: 392
Joined: 25 Jan 2010, 12:21

Re: Problem with hiding a form control check box using code

Post by sdckapr »

So obviously all the form control check boxes have the same #.
I don't think this is always true. Excel may choose to renumber them some starting at 1...
Steve

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Problem with hiding a form control check box using code

Post by ABabeNChrist »

Here is a view of the check box # on the Structure and Exterior sheet
This number is exactly the same at same location for the grounds sheet.
I’m puzzled because I’m referring to a specific sheet and shape
Check box.JPG
You do not have the required permissions to view the files attached to this post.

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Problem with hiding a form control check box using code

Post by ABabeNChrist »

I also tried Jan’s approach and I received this error message.
check box 2.JPG
I tried to duplicate the same approach I used on a new workbook and each and every code mentioned in this thread works great, even though the check boxes had the same # :hairout: :flee: :hairout:
You do not have the required permissions to view the files attached to this post.

User avatar
rory
5StarLounger
Posts: 817
Joined: 24 Jan 2010, 15:56

Re: Problem with hiding a form control check box using code

Post by rory »

That's the macro dialog. It bears no direct relation to the name of the shape.
Regards,
Rory

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Problem with hiding a form control check box using code

Post by ABabeNChrist »

rory wrote:That's the macro dialog. It bears no direct relation to the name of the shape.
When I right click and select veiw code, here is the top part of code refering to this check box
Sub CheckBox29_Click()
If not I'm not sure what you mean

User avatar
Jan Karel Pieterse
Microsoft MVP
Posts: 656
Joined: 24 Jan 2010, 17:51
Status: Microsoft MVP
Location: Weert, The Netherlands

Re: Problem with hiding a form control check box using code

Post by Jan Karel Pieterse »

Control+click on a check box. Then look in the name box to the left of the formula bar to see its name.
Regards,

Jan Karel Pieterse
Excel MVP jkp-ads.com

User avatar
rory
5StarLounger
Posts: 817
Joined: 24 Jan 2010, 15:56

Re: Problem with hiding a form control check box using code

Post by rory »

Then the name is "CheckBox29" and not "Check Box 29" and you are using ActiveX controls, not Forms ones.
Regards,
Rory

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Problem with hiding a form control check box using code

Post by ABabeNChrist »

Jan Karel Pieterse wrote:Control+click on a check box. Then look in the name box to the left of the formula bar to see its name.
Walla, that was it
It didn’t even dawn on me to look in the formula bar; I had it closed off so I didn’t notice
I’m back in bussiness
:bananas:
Thank you Jan, rory and sdckapr