Microsoft Office Tutorials and References
In Depth Information
Using Calendar Control for Office Applications
Dim cmdButton As CommandBarButton¶
Call RemoveCommandBar¶
Set cmdBar = Application.CommandBars.Add("Calendar", Temporary:=True)¶
Set cmdButton = cmdBar.Controls.Add(msoControlButton)¶
With cmdButton¶
'Caption to display on button¶
.Caption = "Calendar"¶
'Procedure name to run when button is clicked¶
.OnAction = "ShowForm"¶
'Style of new command bar button¶
.Style = msoButtonCaption¶
'Show new button¶
.Visible = True¶
End With¶
cmdBar.Visible = True¶
End Sub¶
' * * * * *¶
Public Sub RemoveCommandBar()¶
'Error handler if control is not existing¶
On Error Resume Next¶
'Remove custom control button¶
End Sub¶
' * * * * *¶
Private Sub Document_Close()¶
Call RemoveCommandBar¶
End Sub¶
' * * * * *¶
Private Sub Document_Open()¶
Call CreateCommandBar¶
End Sub¶
The code for this application has four sections. Each must be placed in a
specific place.
1. The first section of code goes in a bas module called basCalendar. The
code shows the UserForm when the calendar needs to be displayed.
2. The second section of code goes in the calendar form called
frmCalendar. This code allows the form to be dynamic in nature
(allowing the selection of dates from months within the range defined in
the code – 1980 to 2099).
3. The third section of code goes in a class module called clsCalendar. This
code is where the class controls required to use the calendar reside.
4. The fourth section of code goes in the ThisX module (where X is either
Workbook or Document, depending on the application) of the project.
Search JabSto ::

Custom Search