Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
calendar Object
I'm trying to use the calendar object in an online form I created. The code I
have was written by Martin Green (http://www.fontstuff.com/word/wordtut03a.htm). It works great on the computer I created the fields with (Word 03) but when I send the form to another computer (Word 02) I get an error message that says "This method or property is not available because the object refers to a protected area of the document." If I unlock the form in Word 02 I can run the macro just fine. The code looks like this (Form Code) Private Sub Calendar1_Click() ' Transfer date selected on calendar to the insertion ' insertion and close UserForm. Selection.Text = Format(Calendar1.Value, "m/d/yy") Selection.MoveRight Unit:=wdCharacter, Count:=1 Unload Me End Sub Private Sub cmdClose_Click() ' Close the form without entering a date if the user ' presses the [ESCAPE] key Unload Me End Sub Private Sub UserForm_Initialize() ' If selection is a date show the same date, otherwise show ' today's date. If IsDate(Selection.Text) Then Calendar1.Value = DateValue(Selection.Text) Else Calendar1.Value = Date End If End Sub The code looks like this (This Document Code) Sub OpenCalendar() ' Display the frmCalendar UserForm frmCalendar.Show End Sub Private Sub Document_Close() On Error Resume Next CustomizationContext = NormalTemplate ' Cancel the keyboard shortcut "Ctrl+Shift+C" KeyBindings.Key(KeyCode:=BuildKeyCode(wdKeyControl , _ wdKeyShift, wdKeyC)).Clear ' Remove the "Insert Date" command from the right-click menu Application.CommandBars("Text").Controls("Insert Date").Delete End Sub Private Sub Document_Open() Dim NewControl As CommandBarControl ' Assign the keyboard shortcut "Ctrl+Shift+C" CustomizationContext = NormalTemplate KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyControl, _ wdKeyShift, wdKeyC), KeyCategory:=wdKeyCategoryMacro, _ Command:="ThisDocument.OpenCalendar" ' Add the "Insert Date" command to the right-click menu Set NewControl = Application.CommandBars("Text").Controls.Add With NewControl ..Caption = "Insert Date" ..OnAction = "ThisDocument.OpenCalendar" ..BeginGroup = True End With End Sub Martin's website says it should work on most versions of Word. Maybe I need the form to unlock, launch the calendar object, and then re-lock? Or, maybe there is another way? Something I'm missing? If you have the time to take a look at this, I would be very appreciative. Jason K. |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
calendar control | Microsoft Word Help | |||
I used a 2006 Word Calendar Template last year, it was calendar wi | New Users | |||
Calendar object | Microsoft Word Help | |||
Adding Border to an object moves the caption!?? | Microsoft Word Help | |||
MS Word Picture Object | Microsoft Word Help |