Monday, March 14, 2011

How to Use Calendar Control in VBA Excel


1. Start Microsoft Office Excel, select the 'Developer' tab then click 'Visual Basic.' Click the 'Insert' menu and select 'UserForm.'
2. Right-click the 'Toolbox' menu and select 'Additional Controls...'. Check the box next to 'Calendar Control 12.0' then click 'OK.'
3. Click the calendar control and add it to 'UserForm1.' Click the 'CommandButton' control and add one to your 'UserForm1.' Double-click the 'CommandButton1' to open Microsoft Visual Basic.
4. Copy and paste the code below inside the 'CommandButton1_Click()' subroutine.Dim dataString As StringdataString = Calendar1.ValueActiveCell = dataStringActiveCell.NumberFormat = 'mm/dd/yy'
5. Press 'F5' to run the program then click 'CommandButton1.' The program will get the calendar date chosen by user and will add it to the active cell in the Excel spreadsheet.

Blogger news