Help Using Calendar Function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I'm using the calendar function so when you click on a calendar icon it
brings up the calendar and when you select the correct date it inserts it
into the relevant cell I want. My trouble is that when you load the calendar
the date it opens at is not "Todays" date. I would like the calendar when
clicked to open to be on todays date - how do I do this?
 
I'm making an assumption that you're using the date picker ActiveX control.
If so, you can place the following code in your workbooks module for the
OnOpen event. Modify the Date Picker name to refernce whatever name you've
assigned to it. If your unsure, open the Control Toolbox tool bar, click the
Design button and the right click on your calendar control and select
properties.

Private Sub Workbook_Open()

Dim dtPicker As dtPicker

Set dtPicker = ActiveWorkbook.Sheets("Sheet1").DTPicker1

dtPicker.Month = Month(Date)
dtPicker.Day = Day(Date)
dtPicker.Year = Year(Date)


End Sub
 
Thanks Kevin, I'll give it a go - DAWN

Kevin B said:
I'm making an assumption that you're using the date picker ActiveX control.
If so, you can place the following code in your workbooks module for the
OnOpen event. Modify the Date Picker name to refernce whatever name you've
assigned to it. If your unsure, open the Control Toolbox tool bar, click the
Design button and the right click on your calendar control and select
properties.

Private Sub Workbook_Open()

Dim dtPicker As dtPicker

Set dtPicker = ActiveWorkbook.Sheets("Sheet1").DTPicker1

dtPicker.Month = Month(Date)
dtPicker.Day = Day(Date)
dtPicker.Year = Year(Date)


End Sub
 
Kevin,

I've tried it, but to be honest I dont know what I am doing.

My calendar which I have an icon on the spreadsheet when pressed it runs a
macro called "show it"

Sub ShowIt()

UserForm2.Show
End Sub

This then brings up a calendar and when I click on the date I want the code
attached to the Form does the below.

End Sub


Private Sub Calendar1_Click()
Range("B7") = Calendar1.Value

End Sub

Private Sub UserForm2_Activate()
Me.Calendar1.Value = Date
End Sub

Private Sub UserForm_Click()

End Sub


This then puts the date I have chosen in my spreadsheet. Where do I put the
code you have given below.

Thanks DAWN
 
Now that I've had some sleep, it was around 1:00 AM when I read your
question, it seems to me that you have standard calendar control on your form.

If you put this in your form's module, for the Initialize event, it well set
the standard calendar control to the current date.

You can use DateSerial(Year, Month, Day) to set it any date you wish, with
the year, month and day being entered as integers.

Hope this helps, if not post again
Private Sub UserForm_Initialize()

Me.Calendar1.Value = Date


End Sub
 
Back
Top