2nd question - Calendar Control 8.0

R

Robert Crandal

I found some code on the Internet that describes how to add
the "Calendar Control 8.0" onto your Excel spreadsheet.
It explains to first create a Userform and then to place the
control on top of the Userform.

The website then explains to paste the following code into your
Userform module:

Private Sub Calendar1_Click()

ActiveCell = Calendar1.Value
ActiveCell.NumberFormat="mm/dd/yy"

End Sub

Private Sub UserForm_Activate()

Me.Calendar1.Value = Date

End Sub

I understand the code for "Calendar1_Click()", but can someone
help me understand the code for "UserForm_Activate()"???
I'm not sure why this code is necessary or what it does?? I am
able to delete the code in "UserForm_Activate()" and the calendar
control still works fine without it, so I just want to know what it does.

Thank you!
 
J

JLatham

The _Activate event fires when the form is activated. That can be upon
initial opening of the form or when you have it open, click on some other
object, such as a worksheet, and then back to the form. So this is a reset
mechanism to set the calendar date back to the system date if you've been
twiddling around on another form, worksheet, or other application. And
you're right, it will work just fine without that code, you just lose that
'reset' function.

Actually, what I'd probably do is to move that line of code into the
UserForm_Initialize()
routine. That would set the date when the form is loaded, leave it alone
while it is in use, and if you use an
Unload Me
statement anywhere, reset it to the current system date the next time you
open the form.
 
M

Mike Fogleman

It is not necessary to put a Calendar on a UseerForm. You can put it right
on the spreadsheet if you want.

Mike F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top