PDA

View Full Version : Solved: Commandbutton visibility



Blackie50
11-22-2010, 03:47 AM
Hi,

I have some commandbuttons created on the worksheet which I don't
want visible on workbook open.

Tried
commandbutton1.visible = false

both in workbook_open (just falls over)
and worksheet_activate (doesn't make them invisible)

Whats the correct way please?

thanks
Jon

Jan Karel Pieterse
11-22-2010, 04:23 AM
The button is a member of the sheet it is on, so:

Sheet1.Commandbutton1.Visible=False
should work.
Provided you are using buttons from the control toolbox (ActiveX).

Blackie50
11-22-2010, 05:01 AM
Thanks for reply.

I created them in 'toolbars', 'visual basic' , 'control toolbox'
and sheet2.commandbutton1.visible = false does not work in either
workbook_open or worksheet_activate.

Any ideas

thanks

Bob Phillips
11-22-2010, 05:11 AM
THis works fine here



Private Sub Worksheet_Activate()
Me.CommandButton1.Visible = False
End Sub

Blackie50
11-22-2010, 06:01 AM
It works with the 'me' but not with sheet2 - however I had renamed sheet2 - maybe thats what the problem was.

thanks for help guys
regards

Jan Karel Pieterse
11-22-2010, 06:28 AM
You must use the codename of the sheet (as shown in the VBA properties window, (name) property).