View Full Version : Solved: Hiding/unhiding Command buttons?

Simon Lloyd
12-07-2007, 08:50 AM
Hi all, i am using the code below to hide command buttons on sheet activate however it will not hide the last clicked button, is it something to do with removing the focus? Here's the code:

Private Sub Worksheet_Activate()
Dim i As Integer
Dim ib As Integer
ActiveSheet.Rows("6:6").Hidden = False
For i = 1 To 6'i used 2 to 6 but changed to 1 to try to cure the problem
With ActiveSheet.Shapes("CommandButton" & i)
.Visible = False
End With
Next i
ActiveSheet.Shapes("CommandButton1").Visible = True
For ib = 1 To 4
With ActiveSheet.Shapes("Combobox" & ib)
.Visible = True
End With
Next ib
End Sub

12-07-2007, 08:56 AM
I suspect you'll find that's not actually the button (which is invisible) but is the image of the button - can you click on it?
Have you tried using Forms toolbar buttons instead, if that's an option?

Edit: actually, I think you can click on it if you do so without clicking anywhere else first; thereafter it's just a 'ghost'

12-07-2007, 09:00 AM
You could also set the TakeFocusOnClick property to False for all of them, but I'd still use the Forms versions if possible.

Simon Lloyd
12-07-2007, 09:10 AM
Thanks for the reply Rory, the TakeFocusOnClick was the one, i understand about the forms buttons but i'm lazy and have already coded all my buttons, placed them, sized them and edited them....so too much trouble for a lazy bloke!

12-07-2007, 09:20 AM
I fully understand! :)