ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Command Button Help (https://www.excelbanter.com/excel-discussion-misc-queries/162076-command-button-help.html)

kenny

Command Button Help
 
I have several command buttons that I need to enable and disable depending on
the one that is clicked currently my code reads like this.

CommandButton1 Click()
CommandButton1.Enabled = False 'because it was clicked
CommandButton2.Enabled = Ture 'because now it can be clicked
CommandButton2.Enabled = Ture 'because now it can be clicked
CommandButton2.Enabled = Ture 'because now it can be clicked

This continues for every commandbutton click procedure. I would like to
rewrite the code to go something like this but I cannot get it to work.
Please Help

Option Explicit
Dim Choice

CommandButtonChoice Sub()
CommandButton1.Enabled = True
CommandButton2.Enabled = True
CommandButton3.Enabled = True
CommandButton4.Enabled = True
Choice.Enabled = False <=============This turns the choice off
End Sub

CommandButton1 Click()
Choice=CommandButton1 <=============Choice to turn off
Call CommandButtonChoice
End Sub

Repeat for each click procedure


OssieMac

Command Button Help
 
Hi again Kenny,

I assume that this is a follow on from my last reply to you. You need to use
Set when assigning and object to a variable.

Option Explicit
Dim Choice As Object

Sub CommandButtonChoice()
MsgBox "CommandButtonChoice() called"
CommandButton1.Enabled = True
CommandButton2.Enabled = True
CommandButton3.Enabled = True
CommandButton4.Enabled = True
Choice.Enabled = False
End Sub

Sub CommandButton1_Click()
MsgBox "CommandButton1_Click()"
Set Choice = CommandButton1
Call CommandButtonChoice
End Sub

Regards,

OssieMac


"Kenny" wrote:

I have several command buttons that I need to enable and disable depending on
the one that is clicked currently my code reads like this.

CommandButton1 Click()
CommandButton1.Enabled = False 'because it was clicked
CommandButton2.Enabled = Ture 'because now it can be clicked
CommandButton2.Enabled = Ture 'because now it can be clicked
CommandButton2.Enabled = Ture 'because now it can be clicked

This continues for every commandbutton click procedure. I would like to
rewrite the code to go something like this but I cannot get it to work.
Please Help

Option Explicit
Dim Choice

CommandButtonChoice Sub()
CommandButton1.Enabled = True
CommandButton2.Enabled = True
CommandButton3.Enabled = True
CommandButton4.Enabled = True
Choice.Enabled = False <=============This turns the choice off
End Sub

CommandButton1 Click()
Choice=CommandButton1 <=============Choice to turn off
Call CommandButtonChoice
End Sub

Repeat for each click procedure


kenny

Command Button Help
 
This worked thanks!


"OssieMac" wrote:

Hi again Kenny,

I assume that this is a follow on from my last reply to you. You need to use
Set when assigning and object to a variable.

Option Explicit
Dim Choice As Object

Sub CommandButtonChoice()
MsgBox "CommandButtonChoice() called"
CommandButton1.Enabled = True
CommandButton2.Enabled = True
CommandButton3.Enabled = True
CommandButton4.Enabled = True
Choice.Enabled = False
End Sub

Sub CommandButton1_Click()
MsgBox "CommandButton1_Click()"
Set Choice = CommandButton1
Call CommandButtonChoice
End Sub

Regards,

OssieMac


"Kenny" wrote:

I have several command buttons that I need to enable and disable depending on
the one that is clicked currently my code reads like this.

CommandButton1 Click()
CommandButton1.Enabled = False 'because it was clicked
CommandButton2.Enabled = Ture 'because now it can be clicked
CommandButton2.Enabled = Ture 'because now it can be clicked
CommandButton2.Enabled = Ture 'because now it can be clicked

This continues for every commandbutton click procedure. I would like to
rewrite the code to go something like this but I cannot get it to work.
Please Help

Option Explicit
Dim Choice

CommandButtonChoice Sub()
CommandButton1.Enabled = True
CommandButton2.Enabled = True
CommandButton3.Enabled = True
CommandButton4.Enabled = True
Choice.Enabled = False <=============This turns the choice off
End Sub

CommandButton1 Click()
Choice=CommandButton1 <=============Choice to turn off
Call CommandButtonChoice
End Sub

Repeat for each click procedure



All times are GMT +1. The time now is 04:38 AM.

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