Problem Statement
In VBA, three main kinds of date time controls can be used provided certain ocxs have been registered using administrator rights. These are VB6 controls and are not native to VBA environment. To install the Montview Control and Datetime Picker, we need to set a reference to Microsoft MonthView Control 6.0 (SP4) which can only be accessed by elevated registration of mscomct2.ocx. Similarly for mscal.ocx and mscomctl.ocx. Having said that, the deprecated mscal.ocx may or may not work on Windows 10.
Depending on your Windows and Office versions (32 bit or 64 bit), it can be really painful to register these ocxs.
The Monthview Control, Datetime Picker and the deprecated Calendar control look like below.
So what problem can I face if I include these in my applicaiton?
If you include them in your project and distribute them to your friends, neighbours, clients etc the application may or may not work depending on whether they have those ocx installed.
And hence it is highly advisable NOT to use them in your project
What alternative(s) do I have?
This calendar, using Userform and Worksheet, was suggested earlier and is incredibly basic.
When I saw the Windows 10 calendar which popped up when I clicked on the date and time from the system tray, I could not help but wonder if we can replicate that in VBA.
This post is about how to create a calendar widget which is not dependant on any ocx or 32bit/64bit and can be freely distributed with your project.
This is what the calendar looks like in Windows 10:
and this is how you interact with it:
This is my first post here. I felt compelled to share as the loss of the calendar in Excel was a huge deal and this calendar SiddhartRout created is incredible. So, MANY thanks to @SiddhartRout for putting together this really amazing calendar. I made changes to the cosmetics but most of the underlying meat of it is still all Siddhart's work with some minor changes to meet my use case.
Cosmetic changes:
Code Changes
Screenshots of each theme:
Download link for code:
The sample file (added at the end of the post) has a Userform, Module and a Class Module. To incorporate this into your project, simply export the Userform, Module and the Class Module from the sample file and import it into your project.
Class Module Code
In the Class Module (Let's call it
CalendarClass
) paste this codeModule Code
In the Module (Let's call it
CalendarModule
) paste this codeUserform Code
The Userform (Let's call it
frmCalendar
) code is too big to be posted here. Please refer to the sample file.Screenshot
Themes
Highlights
Sample File
Sample File
Acknowlegements @Pᴇʜ, @chrisneilsen and @T.M. for suggesting improvements.
What's New:
Bugs reported by @RobinAipperspach and @Jose fixed
Get international day & month names
Just in addition to Sid's valid solution I demonstrate a simplified code to get international weekday and month names - c.f. Dynamically display weekday names in native Excel language
Modified
ChangeLanguage
procedure in form's modulefrmCalendar
Called Functions in
CalendarModule
These three functions could replace the
LanguageTranslations()
function. Advantage: short code, less memory, easier maintenance, correct names