Form control- button with updated date.

johannordgren

New Member
Joined
Apr 24, 2018
Messages
31
Hello there,

Need help with a VBA code or a macro for a clickable button.

When the button is clicked I would like "the text in the button" to update the days date.

Thank you!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hello, If I've understood this correctly, this should do.

My code uses a button named "Button1":

Code:
Sub Button1_Click()
    ActiveSheet.Shapes(Application.Caller).OLEFormat.Object.Text = Date
End Sub

When you click the button, the text on the button will update to reflect the current date.
 
Last edited:
Upvote 0
Hello, If I've understood this correctly, this should do.

My code uses a button named "Button1":

Code:
Sub Button1_Click()
    ActiveSheet.Shapes(Application.Caller).OLEFormat.Object.Text = Date
End Sub

When you click the button, the text on the button will update to reflect the current date.

Hmm, doesn't work for me, says the code is wrong :/ And yes, I've renamed my bitton to "Button1"
 
Upvote 0
Hi,
try

Code:
Sub Button1_Click()
    ActiveSheet.Buttons("Button 1").Caption = Format(Date, "dd/mm/yyyy")
End Sub

Dave
 
Upvote 0
Error 1004
"Unable to get the Buttons property of the worksheec class"

Guess I'm doing something wrong..

Is your sheet protected?

if so, try this update

Code:
Sub Button1_Click()
    With ActiveSheet
    .Unprotect Password:=""
        .Buttons("Button 1").Caption = Format(Date, "dd/mm/yyyy")
    .Protect Password:=""
    End With
End Sub

add password as required

Dave
 
Last edited:
Upvote 0
Hmm, doesn't work for me, says the code is wrong :/ And yes, I've renamed my bitton to "Button1"

If you're willing to take another shot with mine, you can right click the button and use "assign macro" then make sure the Button1_click is actually selected.

For the record, I'm having success with my code and Dave's code (though my 'merican date format doesn't match Dave's) :P
 
Upvote 0

Forum statistics

Threads
1,213,535
Messages
6,114,192
Members
448,554
Latest member
Gleisner2

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