ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Date picker control (https://www.excelbanter.com/excel-programming/384090-date-picker-control.html)

GeraldM

Date picker control
 
I have added two date picker controls to a worksheet.

On one control:
I would like to default to today's date whenever the workbook is opened.

On the other control:
I would like to default the date to today + 2 weeks.

How do i set a default value for these controls?


-- Thanks in advance

OssieMac

Date picker control
 
Open VBA Editor ans select This Workbook in the project browser
Something similar to this in a workbook open event.

Private Sub Workbook_Open() 'Must be this sub name
Dim TodaysDate As Date
Dim TodayFortnightDate As Date
Sheets("ExcelControls").Select 'Use your sheet name
TodaysDate = Date
TodayFortnightDate = Date + 14
Sheets("ExcelControls").CommandButton1.Caption = Format _
(TodaysDate, "dd/mm/yyyy")
Sheets("ExcelControls").CommandButton2.Caption = Format _
(TodayFortnightDate , "dd/mm/yyyy")
End Sub




"GeraldM" wrote:

I have added two date picker controls to a worksheet.

On one control:
I would like to default to today's date whenever the workbook is opened.

On the other control:
I would like to default the date to today + 2 weeks.

How do i set a default value for these controls?


-- Thanks in advance


OssieMac

Date picker control
 
I have had another read of your request and now I am not sure whether it is
the default value to process that you want to change or the caption. If it is
the value then basically the same but substitue caption with value and you
may be able to leave the format function out. However, you cannot set a value
for a control button and I don't know what sort of control you have so my
example is for a ComboBox
eg. Sheets("ExcelControls").ComboBox1.Value = TodaysDate


"OssieMac" wrote:

Open VBA Editor ans select This Workbook in the project browser
Something similar to this in a workbook open event.

Private Sub Workbook_Open() 'Must be this sub name
Dim TodaysDate As Date
Dim TodayFortnightDate As Date
Sheets("ExcelControls").Select 'Use your sheet name
TodaysDate = Date
TodayFortnightDate = Date + 14
Sheets("ExcelControls").CommandButton1.Caption = Format _
(TodaysDate, "dd/mm/yyyy")
Sheets("ExcelControls").CommandButton2.Caption = Format _
(TodayFortnightDate , "dd/mm/yyyy")
End Sub




"GeraldM" wrote:

I have added two date picker controls to a worksheet.

On one control:
I would like to default to today's date whenever the workbook is opened.

On the other control:
I would like to default the date to today + 2 weeks.

How do i set a default value for these controls?


-- Thanks in advance



All times are GMT +1. The time now is 04:54 PM.

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