Disable button after first use/enable again after re-opening file

CutterSoilMixing

New Member
Joined
Jun 8, 2019
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

I created a command button from the ActiveX controls. I want it to add +1 to a certain cell, update the date in another cell, disable after clicking it once and re-enable after closing and opening the excel file. I got everything working but the re-enabling... please help, this is my first experience with VBA, macros etc.

Here's my code:

Private Sub CommandButton1_Click()
[BF5].Value = [BF5].Value + 1
[AZ6].Value = "=TODAY()"
CommandButton1.Enabled = False


End Sub


Sub Auto_Open()
CommandButton1.Enabled = True


End Sub

Thanks!
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi & welcome to MrExcel
Try this in the ThisWorkbook module
Code:
Private Sub Workbook_Open()
Sheets("sheet1").CommandButton1.Enabled = True
End Sub
Change sheet name to suit
 
Upvote 0
Hi & welcome to MrExcel
Try this in the ThisWorkbook module
Code:
Private Sub Workbook_Open()
Sheets("sheet1").CommandButton1.Enabled = True
End Sub
Change sheet name to suit

Thanks for your reply and the welcome!

I tried your code but I'm not sure if I did it correctly. Here's my code:

Code:
 Private Sub CommandButton1_Click()[BF5].Value = [BF5].Value + 1
[AZ6].Value = "=TODAY()"
CommandButton1.Enabled = False


End Sub
Private Sub Workbook_Open()
CommandButton1.Enabled = True
End Sub

I'm not sure what the ThisWorkbook module is...as I said before, very inexperienced!

Thanks!
 
Upvote 0
In the VB editor you should have a window entitled "project" (top left of the editor) which has a list of the sheets & modules in the workbook.
One of those will be entitled ThisWorkbook, double click on that and paste this
Code:
Private Sub Workbook_Open()
Sheets("[COLOR=#ff0000]sheet1[/COLOR]").CommandButton1.Enabled = True
End Sub
into the codewindow that opens up.
You will need to change the part in red to match the name of the sheet containing the button
 
Upvote 0

Forum statistics

Threads
1,215,008
Messages
6,122,672
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top