Thursday, April 26, 2018

variables need to be explicitly declared even though óption explicit'option not given

INTRODUCTION
1. It is considered a good practice to use óption explicit'at the beginning of a module or code block, doing so, will need unique declaration of each variable in the module.

2. Though, this is good for organized coding, it can take the fun out of quick coding.

PROBLEM
1. I had not used option explicit anywhere, however, when a excel macro file developed elsewhere, was copied to my system, the code execution stopped at each undeclared variable. Declaring that variable solved the issue, however, code will stop at the next undeclared variable.

2. I checked the options menu in VB editor, "require variable declaration was also unchecked". This was a huge problem as I may have had dozens of undeclared variables. Why was I facing this problem in my home laptop while elsewhere it worked?

3. googled, found someone else also faced the same problem. The issue was using "References"which are not installed (Active X controls, like comctl2.ocx etc).

4. Clicked Tools-->References, and indeed there was highlighted a checkbox with "Missing: common controls (SP6). Unchecked this missing reference, and everything solved.  The code did not stop at any undeclared variable.

5. Meanwhile installed the common control active x and got the functionality was also obtained (separate blog post created for same)
 

making date time picker controls (sp6) work in Excel 2007

1. It is better to install MS office as 32 bit software even in 64 bit systems if legacy VBA code is being used in some excel files.

2. The common controls (mscomct2.ocx) will not work if office installed as 64 bit application.

3. The common control components like Microsoft Date time picker are obtained if the mscomct2.ocx active x file is added to the system.

4. Do not confuse between Mscomctl.ocx and mscomct2.ocx. The former is used for VB6 and later is used for VBA. download the correct ocx file and register to get the date time picker control in Excel VBA.

5. see this link (or google, if this does not open) for procedure to register active x controls.
https://www.ablebits.com/office-addins-blog/2016/10/12/insert-calendar-excel-datepicker-template/#Register-date-picker

6. irrespective, if your application is installed as 32 bit (meaning it is stored c:\program files (x86) ) in the 64 bit OS system , the OCX file has to be copied to C:\windows\syswow64 and then procedure as mentioned in step 5 to be applied.  The 64 bit applications are stored in normal program files folder (C:\program files)

7. By doing step 5 & 6, the date time picker control started appearing in VBA of excel.