View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default disable pushbutton on spreadsheet

I had this in a General module:

Option Explicit
Sub testme()
UserForm1.Show False
End Sub

This was the macro that I assigned to the button from the Forms toolbar. The
button was on Sheet1 and named "Button 1".

If you used a commandbutton from the control toolbox toolbar, then this code was
behind the worksheet that held that commandbutton:

Option Explicit
Private Sub CommandButton1_Click()
UserForm1.Show False
End Sub

The name of this button was "CommandButton1".


I didn't know what kind of button you used on the sheet.

Then my userform had a commandbutton that would cancel the userform. This was
named Commandbutton2.

This is the code that was behind the Userform.

Option Explicit
Private Sub CommandButton2_Click()
'cancel button on the userform
ThisWorkbook.Worksheets("sheet1").Buttons("button 1").Enabled = True
ThisWorkbook.Worksheets("Sheet1").CommandButton1.E nabled = True
Unload Me
End Sub
Private Sub UserForm_Initialize()
ThisWorkbook.Worksheets("sheet1").Buttons("button 1").Enabled = False
ThisWorkbook.Worksheets("Sheet1").CommandButton1.E nabled = False
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Call CommandButton2_Click
End If
End Sub

Delete the pair of lines (commandbutton or "button 1") depending on what kind of
button you used.
Remember to change the sheetname and the button/commandbutton to match what you
need.

ps. When the commandbutton was disabled, it looked disabled. The button from
the Forms toolbar didn't look as nice. (You could change the code to hide/show
it or even change the colors/caption if that was a problem.)





Robert Crandal wrote:

Is it possible to disable a pushbutton that is placed on
top of my spreadsheet?? Basically, if the button is
pressed I will display my userform object. If the
userform is visible/loaded, I want the button to be
disabled. Then, when the userform is closed out
I want to re-enable the button again.

thank u


--

Dave Peterson