ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how do you hide a forms command button (https://www.excelbanter.com/excel-programming/276138-how-do-you-hide-forms-command-button.html)

Paul James[_3_]

how do you hide a forms command button
 
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.



Dave Peterson[_3_]

how do you hide a forms command button
 
This is from the Forms toolbar?

Worksheets("Sheet1").Buttons("cmdEnterData").Visib le = 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.

Paul James wrote:

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.


--

Dave Peterson


jim C.

how do you hide a forms command button
 

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


Hope this helps...

-----Original Message-----
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.


.


jim C.

how do you hide a forms command button
 
sorry, missed the button is on the worksheet and not a
userform...




-----Original Message-----
This is from the Forms toolbar?

Worksheets("Sheet1").Buttons("cmdEnterData").Visi ble =

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.

Paul James wrote:

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.


--

Dave Peterson

.


Dave Peterson[_3_]

how do you hide a forms command button
 
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



Paul James wrote:

Thanks to Dave and Jim.

You're right, Dave, I do like the idea of the Enabled property. Question
about that, however. If I used it, I'd like to be able to gray it out,
because if you don't, the user has no visual cue that it's been disabled,
and it might create confusion when he clicks on it. Whereas if it's grayed
out, he's got a visual cue that it's been disabled, presumably for a good
reason.

Is there a property that enables me to gray out the button when the Enabled
property is set to False?

Thanks again.


--

Dave Peterson



All times are GMT +1. The time now is 09:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com