how do you hide a forms command button

  • Thread starter Thread starter Paul James
  • Start date Start date
P

Paul James

I need to be able to hide and display a command button depending on the
occurrence of certain events. What code can I use to hide and display a
command button named "cmdEnterData"?

Thank you in advance.
 
This is from the Forms toolbar?

Worksheets("Sheet1").Buttons("cmdEnterData").Visible = True

There's another property that you might like, too: .enabled = True/False

The button will still be there, but won't do anything if you click it.
 
If ??? True Then
cmdEnterData.Visible = True
Else
cmdEnterData.Visible = False
End If


Hope this helps...
 
I don't think you'll be able to change the color of the button (of the forms
button, you could do it with the controltoolbox toolbar button).

But you could change the fontcolor of the characters on the button (or maybe
strikethrough the characters). Or you could leave the button active and just
assign it to a macro that yells at them.

Maybe you could pick and choose from this snippet.

Option Explicit
Sub testme()

Dim myBtn As Button

Set myBtn = Worksheets("Sheet1").Buttons("cmdEnterData")
With myBtn
.Enabled = True
.Font.ColorIndex = 12
.Font.Strikethrough = True
.OnAction = ThisWorkbook.Name & "!MacroNotAvailable"
End With

End Sub

Sub MacroNotAvailable()
MsgBox "Not available"
End Sub
 
Back
Top