You are on page 1of 12

CalendarForm v1.5.

2 Develope

This custom date picker can be used by importing the CalendarForm.frm file into your VBA project. It is called exclus
For instructions on how to call on the CalendarForm, skip to the GetDate function documentation on the Us

Overview

The goal in creating this form was first and foremost to overcome the monstrosity that is the Microsoft MonthView c
probably already know what I'm talking about. Many others have been in my place and have come up with their own
So why yet another custom date picker?

I was most interested in the following features:


Ease of use. I wanted a completely self-contained form that could be imported into any VBA project and used withou
Simple, attractive design. While a lot of custom date pickers on the internet look good and work well, none of them q
style and UI design.
Fully customizable functionality and look. I tried to include as many of the options from the MonthView control as I c

Since none of the date pickers I have been able to find in all my searching have quite completed my checklist, here w
other tired soul may also benefit from my labors.

If you encounter any bugs, or have any great ideas or feature requests that could improve this bad boy, please send m
Developed by Trevor Eyre (trevoreyre@gmail.com)

project. It is called exclusively through the GetDate function.


documentation on the Using GetDate Function tab.

Microsoft MonthView control. If you're reading this, you


come up with their own date pickers to solve this problem.

project and used without any additional coding.


work well, none of them quite nailed it for me in terms of

MonthView control as I could, without getting too messy.

ted my checklist, here we are! Now my hope is that some

is bad boy, please send me an email.


CalendarForm v1.5.2 Develope

Using the GetDate Function

The GetDate function is the point of entry into the CalendarForm. It controls EVERYTHING. Every argument is optiona
be as simple as dateVariable = CalendarForm.GetDate.

That's all there is to it. The calendar initializes, pops up, the user selects a date, the selection is received by your varia

Try it out! Click the calendar to select a date to show in the box.
VBA Code

###
Sub BasicCalendar()
January 7, 2016 dateVariable = Calend
If dateVariable <> 0 T
End Sub

From there, you can use as many or as few arguments as you want in order to get the desired calendar that suits you
set in the GetDate function, so if you want to change default colors or behavior without having to explicitly do so in e
those values in the argument list for the function.

By setting the various arguments, you can obtain vastly different calendars, all with the same function. Below is an ex
different settings, including week numbers, a different first day of the week, and a customized color scheme.

VBA Code

### Sub AdvancedCalendar()


January 7, 2016 dateVariable = CalendarF
SelectedDate:=Range(
FirstDayOfWeek:=Mon
DateFontSize:=12, _
TodayButton:=True, _
OkayButton:=True, _
ShowWeekNumbers:=
BackgroundColor:=RGB
HeaderColor:=RGB(14
HeaderFontColor:=RGB
SubHeaderColor:=RGB
SubHeaderFontColor:=
DateColor:=RGB(243, 2
DateFontColor:=RGB(3
TrailingMonthFontColo
DateHoverColor:=RGB
DateSelectedColor:=RG
SaturdayFontColor:=RG
SundayFontColor:=RGB
TodayFontColor:=RGB(
If dateVariable <> 0 Then
SubHeaderColor:=RGB
SubHeaderFontColor:=
DateColor:=RGB(243, 2
DateFontColor:=RGB(3
TrailingMonthFontColo
DateHoverColor:=RGB
DateSelectedColor:=RG
SaturdayFontColor:=RG
SundayFontColor:=RGB
TodayFontColor:=RGB(
If dateVariable <> 0 Then
End Sub

Below is another example of ways you can customize the look and feel of your calendar.

VBA Code

### Sub AdvancedCalendar2()


dateVariable = CalendarF
January 7, 2016 SelectedDate:=Range(
DateFontSize:=11, _
TodayButton:=True, _
BackgroundColor:=RGB
HeaderColor:=RGB(84
HeaderFontColor:=RGB
SubHeaderColor:=RGB
SubHeaderFontColor:=
DateColor:=RGB(242, 2
DateFontColor:=RGB(5
SaturdayFontColor:=RG
SundayFontColor:=RGB
TrailingMonthFontColo
DateHoverColor:=RGB
DateSelectedColor:=RG
TodayFontColor:=RGB(
DateSpecialEffect:=fmS
If dateVariable <> 0 Then
End Sub

For a complete list of arguments, their data type, and a description of its function, go to the GetDate Arguments tab
documented in the CalendarForm userform itself.
Developed by Trevor Eyre (trevoreyre@gmail.com)

very argument is optional, meaning your function call can

is received by your variable, and the calendar unloads.

Sub BasicCalendar()
dateVariable = CalendarForm.GetDate
If dateVariable <> 0 Then Range("H16") = dateVariable
End Sub

d calendar that suits your needs. All default values are also
ng to explicitly do so in every function call, you can set

e function. Below is an example of a calendar with some


d color scheme.

b AdvancedCalendar()
dateVariable = CalendarForm.GetDate( _
SelectedDate:=Range("H34").Value, _
FirstDayOfWeek:=Monday, _
DateFontSize:=12, _
TodayButton:=True, _
OkayButton:=True, _
ShowWeekNumbers:=True, _
BackgroundColor:=RGB(243, 249, 251), _
HeaderColor:=RGB(147, 205, 2221), _
HeaderFontColor:=RGB(255, 255, 255), _
SubHeaderColor:=RGB(223, 240, 245), _
SubHeaderFontColor:=RGB(31, 78, 120), _
DateColor:=RGB(243, 249, 251), _
DateFontColor:=RGB(31, 78, 120), _
TrailingMonthFontColor:=RGB(155, 194, 230), _
DateHoverColor:=RGB(223, 240, 245), _
DateSelectedColor:=RGB(202, 223, 242), _
SaturdayFontColor:=RGB(0, 176, 240), _
SundayFontColor:=RGB(0, 176, 240), _
TodayFontColor:=RGB(0, 176, 80))
f dateVariable <> 0 Then Range("H34") = dateVariable
SubHeaderColor:=RGB(223, 240, 245), _
SubHeaderFontColor:=RGB(31, 78, 120), _
DateColor:=RGB(243, 249, 251), _
DateFontColor:=RGB(31, 78, 120), _
TrailingMonthFontColor:=RGB(155, 194, 230), _
DateHoverColor:=RGB(223, 240, 245), _
DateSelectedColor:=RGB(202, 223, 242), _
SaturdayFontColor:=RGB(0, 176, 240), _
SundayFontColor:=RGB(0, 176, 240), _
TodayFontColor:=RGB(0, 176, 80))
f dateVariable <> 0 Then Range("H34") = dateVariable
d Sub

b AdvancedCalendar2()
dateVariable = CalendarForm.GetDate( _
SelectedDate:=Range("H61").Value, _
DateFontSize:=11, _
TodayButton:=True, _
BackgroundColor:=RGB(242, 248, 238), _
HeaderColor:=RGB(84, 130, 53), _
HeaderFontColor:=RGB(255, 255, 255), _
SubHeaderColor:=RGB(226, 239, 218), _
SubHeaderFontColor:=RGB(55, 86, 35), _
DateColor:=RGB(242, 248, 238), _
DateFontColor:=RGB(55, 86, 35), _
SaturdayFontColor:=RGB(55, 86, 35), _
SundayFontColor:=RGB(55, 86, 35), _
TrailingMonthFontColor:=RGB(106, 163, 67), _
DateHoverColor:=RGB(198, 224, 180), _
DateSelectedColor:=RGB(169, 208, 142), _
TodayFontColor:=RGB(255, 0, 0), _
DateSpecialEffect:=fmSpecialEffectRaised)
f dateVariable <> 0 Then Range("H61") = dateVariable
d Sub

GetDate Arguments tab. This information is also


CalendarForm v1.5.2 Develope

GetDate Arguments

Below is a list of all arguments in the GetDate function, their data type, and their function. Remember that every arg
meaning you can use as many or as few as you want to meet your needs.

SelectedDate (Date) - This is the initial selected date on the calendar. Used to show the users last selection. If this va
to the month and year of the SelectedDate. If not, it will initialize to today's date (with no selection).
FirstDayOfWeek (calDayOfWeek) - Sets which day to use as first day of the week.

MinimumDate (Date) - Restricts the selection of any dates below this date.
MaximumDate (Date) - Restricts the selection of any dates above this date.
###
RangeOfYears (Long) - Sets the range of years to show in the year combobox in either direction from the initial Selec
SelectedDate is in 2014, and the RangeOfYears is set to 10 (the default value), the year combobox will show 10 years
2014, so it will have a range of 2004-2024. Note that if this range falls outside the bounds set by the MinimumDate o
overridden. Also, this range does NOT limit the years that a user can select. If the upper limit of the year combobox i
month spinner to surpass December 2024, it will keep right on going to 2025 and beyond (and those years will be ad

DateFontSize (Long) - Controls the size of the CalendarForm. This value cannot be set below 9 (the default). To make
larger, and everything else in the userform will be resized to fit.

TodayButton (Boolean) - Controls whether or not the Today button is visible.

OkayButton (Boolean) - Controls whether or not the Okay button is visible. If the Okay button is enabled, when the u
but is not returned until they click Okay. If the Okay button is disabled, clicking a date will automatically return that d

ShowWeekNumbers (Boolean) - Controls the visibility of the week numbers.

FirstWeekOfYear (calFirstWeekOfYear) - Controls which week in January is calculated as week 1. See the calFirstWee
Variables section of the CalendarForm to see the possible values and their behavior.
PositionTop (Long) - Sets the top position of the CalendarForm. If no value is assigned, the CalendarForm is set to po
PositionTop and PositionLeft must BOTH be set in order to override the default center position.

PositionLeft (Long) - Sets the left position of the CalendarForm. If no value is assigned, the CalendarForm is set to po
PositionTop and PositionLeft must BOTH be set in order to override the default center position.
###
BackgroundColor (Long) - Sets the background color of the CalendarForm.

HeaderColor (Long) - Sets the background color of the header. The header is the month and year label at the top.

HeaderFontColor (Long) - Sets the color of the header font.

SubHeaderColor (Long) - Sets the background color of the subheader. The subheader is the day of week labels under

DateColor (Long) - Sets the background color of the individual date labels.
DateFontColor (Long) - Sets the font color of the individual date labels.

SaturdayFontColor (Long) - Sets the font color of Saturday date labels.

SundayFontColor (Long) - Sets the font color of Sunday date labels.

DateBorder (Boolean) - Controls whether or not the date labels have borders.

DateBorderColor (Long) - Sets the color of the date label borders. Note that the argument DateBorder must be set to
DateFontColor (Long) - Sets the font color of the individual date labels.

SaturdayFontColor (Long) - Sets the font color of Saturday date labels.


SundayFontColor (Long) - Sets the font color of Sunday date labels.

DateBorder (Boolean) - Controls whether or not the date labels have borders.

DateBorderColor (Long) - Sets the color of the date label borders. Note that the argument DateBorder must be set to

DateSpecialEffect (fmSpecialEffect) - Sets a special effect for the date labels. This can be set to bump, etched, flat (de
can be used to make the date labels look like buttons if you desire. Note that this setting overrides any date border s

DateHoverColor (Long) - Sets the background color when hovering the mouse over a date label.

DateSelectedColor (Long) - Sets the background color of the selected date.

TrailingMonthFontColor (Long) - Sets the color of the date labels in trailing months. Trailing months are the date labe
the calendar and from next month at the bottom of the calendar.

TodayFontColor (Long) - Sets the font color of today's date.


Developed by Trevor Eyre (trevoreyre@gmail.com)

emember that every argument in the function is optional,

s last selection. If this value is set, the calendar will initialize


lection).

tion from the initial SelectedDate. For example, if the


bobox will show 10 years below 2014 to 10 years above
t by the MinimumDate or MaximumDate, it will be
t of the year combobox is 2024, and the user clicks the
nd those years will be added to the year combobox).

9 (the default). To make the form bigger, set this value

n is enabled, when the user selects a date, it is highlighted,


tomatically return that date and unload the form.

k 1. See the calFirstWeekOfYear Enum in the Global

alendarForm is set to position 1 - CenterOwner. Note that


on.

alendarForm is set to position 1 - CenterOwner. Note that


on.

year label at the top.

day of week labels under the header (Su, Mo, Tu, etc).

ateBorder must be set to True for this setting to take effect.


ateBorder must be set to True for this setting to take effect.

to bump, etched, flat (default value), raised, or sunken. This


rrides any date border settings you have made.

bel.

months are the date labels from last month at the top of

You might also like