I am using a couple of Microsoft Date and Time Picker 6.0 (SP4) controls within my Excel workbook. I would like for these controls to automatically fetch the current date. How can I do this?
Sorry if this is within the wrong subforum.
Last edited by SP Brian; 03-16-2010 at 06:57 PM.
Any feedback?
Where are the controls? On a userform or a worksheet?
So long, and thanks for all the fish.
Within a worksheet.
I thought the default was the current date, try
Code:Private Sub Worksheet_Activate() Me.DTPicker1.Value = Date End Sub
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
Check out the free Excel Toolbar
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Code Tags: Make your code easier for us to read
Could you break the code down for me, please? Sorry for my ignorance when it comes to code. I know that "sub" means subroutine and that DTPicker1 is the name of the picker and that ".Value" means that I am setting the value of the DTPicker1 to equal "Date". Does "Date" fetch the system date or how does that work?
Also, what does Private Sub Worksheet_Activate() mean?
Date() does indeed return the current system date.
The Worksheet_Activate event fires whenever you activate the worksheet containing the code.
So long, and thanks for all the fish.
The code works; however, upon opening the .xlsx file the worksheet opened is the one containing the date picker, so the control is only updated with the current date after I enabled ActiveX/Macros and switch to a different sheet then back to the sheet containing the control.
Is there a way that I can make this take effect upon the user enabling the ActiveX/Macros?
Last edited by SP Brian; 03-16-2010 at 06:38 PM.
Yes - you need to use the Workbook_OPen event. This code needs to go into the ThisWorkbook module:
Code:Private Sub Workbook_Open() Sheets("Sheet name").DTPicker1.Value = Date End Sub
So long, and thanks for all the fish.
Works like a charm. Thank you!
If you are satisfied with the solution(s) provided, please mark your thread as Solved.
How to mark a thread Solved
Go to the first post
Click edit
Click Go Advanced
Just below the word Title you will see a dropdown with the word No prefix.
Change to Solved
Click Save
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
Check out the free Excel Toolbar
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Code Tags: Make your code easier for us to read
What would the code be for putting the date picker in a userform? thanks!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks