View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
Trefor Trefor is offline
external usenet poster
 
Posts: 201
Default Disable Userform button

Dave,

Indeed a simple one line version of Peter's code, but this does not "grey
out" the button. To me this leave the user wondering why the button is not
working, "grey'd out" makes it clear that it has been disabled for some
reason.

Apart from the early Exit Sub, I have a Msgbox, stating that the button had
been disabled, I just thought there may be a more elegant way of doing this
--
Trefor


"Dave Peterson" wrote:

worksheets("sheet1").buttons("button 1").enabled = false

For the easy response.

Trefor wrote:

Peter/Bob/Dave,

Thankyou all for your replies and yes my "new guy" terminology finally got
deciphered by Peter, yes indeed a €œsheet with a button from the forms
toolbar€.

Dave, Currently I set a variable to €œdisabled€ on a certain event, each
macro that runs from the button checks this variable and if set to €œdisabled€
simply does an Exit Sub and the macro obviously does not run.

Peter your code does indeed disable the button and forces the colour of the
text to grey and then back to black afterwards, thankyou for this.
Unfortunately the button colour is not black (its blue) and in some cases has
two different colours (Red and Blue). The disable on the CommandButton on a
sheet from the Control Toolbox seemed to be neat and easy, but clearly not so
neat on a button from the forms toolbar? I presume there is a way to check
the colour on the button, save it to a variable and return it when finished,
but I presume this would be all too hard with multiple colours?

--
Trefor

"Peter T" wrote:

Trefor,

Following Bob's observation about your button named "Button 30", I guess it
is neither a userform button nor a Commanbutton but a button on a sheet
applied with the Forms toolbar. If so try this in a Normal module

Sub TestEnable()
EnableButton "Button 30", True

End Sub

Sub TestDisable()
EnableButton "Button 30", False

End Sub

Function EnableButton(sBtnName As String, bEnable As Boolean)
Dim btn As Button

On Error Resume Next
Set btn = ActiveSheet.Buttons(sBtnName)

If btn Is Nothing Then
MsgBox sBtnName & " does not exist on this sheet"
Else
btn.Enabled = bEnable

'simulate greyed out text if disabled
btn.Font.Color = IIf(bEnable, 0, RGB(150, 150, 150))
End If

End Function

Regards,
Peter T


"Bob Phillips" wrote in message
...
Trefor,

You may not know it, but userform code modules are a specific type of
class
module. If you want to disable a button on a userform, there must be
something, some situation, that will determine when that button is to be
disabled. What is that?

Also, as you call it Button 30, it makes me think that you are referring
to
worksheets not a userform at all. Can you clarify?



--

HTH

RP
(remove nothere from the email address if mailing direct)


"Trefor" wrote in message
...
Chip,

Sorry I am new to VBA and whatever you just said went way over the top
of
my
head! ;)

As for Class modules, I have not got passed Modules yet. Can you help me
out
this some code for a Module please?

--
Trefor


"Chip Pearson" wrote:

The keyword 'Me' refers to the object that contains it. So for a
class module, it refers to that instance of the class, for a
userform, it refers to the form, etc.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Trefor" wrote in message
...
Bob,

Sorry what is "Me"?

And for "Button 30" is it CommandButton30? Can you use
CommandButton(1)?
--
Trefor


"Bob Phillips" wrote:

Exactly the same

Me.CommandButton1.Enabled = False


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Trefor" wrote in message
...
From another thread I worked how to disable and "grey out" a
"commandbutton",
but I am using a Userforms "Button" is it possible to grey
out this type
of
button?

--
Trefor













--

Dave Peterson