how do you hide a forms command button

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.
 
D

Dave Peterson

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.
 
J

jim c.

If ??? True Then
cmdEnterData.Visible = True
Else
cmdEnterData.Visible = False
End If


Hope this helps...
 
D

Dave Peterson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top