#1
|
|||
|
|||
word 2003 date picker
Hello,
I wanted to know if it is possible to add a date picker in a Microsoft word 2003 document. I am trying to create a word 2003 document for users to select and enter specific fields and select the required date using the date picker. I would really appreciate any help. Thanks ! |
#2
|
|||
|
|||
There is no date picker in 2003. You can add a calendar control and some VBA to insert the selected date in the document.
The calendar control can be found at Insert > Object > Calendar control To do the VBA, start by typing 11 characters in the doc where you want the date to be displayed (these 11 characters will be replaced by the date). Turn on the macro recorder and press Ctrl+Home to go to the top of the doc, then use the keyboard to navigate to and select the 11 characters. Turn off the recorder. View the macro code and copy the lines that start with "Selection" Exit the code window Double click on the calendar control Between the Private Sub and End Sub lines, paste the lines from the previous macro Just before the End Sub line, add this line: Code:
Selection.Text = Format(Calendar1.Value, "mmm dd yyyy") Code:
Private Sub Calendar1_Click() Selection.HomeKey Unit:=wdStory Selection.MoveDown Unit:=wdLine, Count:=10 Selection.MoveRight Unit:=wdCharacter, Count:=11, Extend:=wdExtend Selection.Text = Format(Calendar1.Value, "mmm dd yyyy") End Sub Exit design mode of the Calendar Control Test If it works, delete the original macro that you recorded. |
#3
|
|||
|
|||
Hi,
I followed the steps but it places the date somewhere else and not at the 11 characters place. Here is the VBA code that I have. code: Private Sub Calendar1_Click() Selection.HomeKey Unit:=wdStory Selection.MoveDown Unit:=wdLine, Count:=10 Selection.MoveRight Unit:=wdCharacter, Count:=11, Extend:=wdExtend Selection.Text = Format(Calendar1.Value, "mmm dd yyyy") Selection.MoveDown Unit:=wdLine, Count:=54 Selection.MoveRight Unit:=wdCharacter, Count:=15 Selection.MoveDown Unit:=wdLine, Count:=2 Selection.MoveRight Unit:=wdCharacter, Count:=11, Extend:=wdExtend Selection.Text = Format(Calendar1.Value, "mmm dd yyyy") End Sub Thanks for your help. |
#4
|
|||
|
|||
You have a couple of lines in there that are repeated, but should only be present once. I think you used my code and tacked yours on the end.
Start over. Turn on the macro recorder and do these steps:
Then post that code. |
#5
|
|||
|
|||
By the way, I hope I'm not wasting your time. This code assumes the document will not change...
the code will always navigate a number of lines down and a number of characters to the right, then select 11 characters and replace them with a date. If the 11 characters will move due to additions or deletions above them, we'll need to do it differently. |
#6
|
|||
|
|||
Actually the document will change as it is a template and users will be filling up the fields. Do we need a different code for this?
The Date fields are somewhere in between the documents. Than you ! |
#7
|
|||
|
|||
You could type this text in the document where you want the date:
Date: TheDateMark (that is, the word "date", a colon, a space, and then 11 characters to be replaced by the code) This code will find the text Date<space>:, and replace the 11 characters that follow it with the date. Code:
Private Sub Calendar1_Click() Selection.HomeKey Unit:=wdStory Selection.Find.ClearFormatting With Selection.Find .Text = "Date: " .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.MoveRight Unit:=wdCharacter, Count:=1 Selection.MoveRight Unit:=wdCharacter, Count:=11, Extend:=wdExtend Selection.Text = Format(Calendar1.Value, "mmm dd yyyy") End Sub |
#8
|
|||
|
|||
Yes, this does replace the date with one selected in the calendar. Is it possible to add an additional calender in the document. will the code remain the same?
Thank you ! |
#9
|
|||
|
|||
If the second calendar is for a second date field, just use different text to mark the beginning of the date (don't use Date: again) in both the document and the code for the second calendar.
|
#10
|
|||
|
|||
Thank you very much ! The code works but the only thing left is that I need to protect the document as I have inserted some form controls like drop down lists in the template. Now when I select a date in the calendar, it gives a runtime error.
I am guessing this has to be a limitation within word. |
#11
|
|||
|
|||
Record a macro that unprotects the doc.
Record a macro that protects the doc. Paste the unprotect code to the start of the Calendar code Paste the protect code at the end of the calendar code. So when the calendar is clicked, the code will unprotect, do the date, then re-protect. |
#12
|
|||
|
|||
I am trying to use the second calendar for a second date and as you mentioned I used 2 different texts for the dates which are
1. "EffectiveDate: " 2. "ExpirationDate:" In this case only the first calendar works and the 2nd calendar is set to the first calendars date only when clicked. How will I be able to overcome this. Thank you ! |
#13
|
|||
|
|||
By default the first calendar you insert is named Calendar1
By default the second calendar you insert is named Calendar2 (right-click on a calendar and choose Properties to see this) So if Calendar1 is for EffectiveDate: , the code should look like: Code:
Private Sub Calendar1_Click() Selection.HomeKey Unit:=wdStory Selection.Find.ClearFormatting With Selection.Find .Text = "EffectiveDate: " .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.MoveRight Unit:=wdCharacter, Count:=1 Selection.MoveRight Unit:=wdCharacter, Count:=11, Extend:=wdExtend Selection.Text = Format(Calendar1.Value, "mmm dd yyyy") End Sub |
#14
|
|||
|
|||
Sorry for the trouble but I believe we may not have to use macros in the form/template. Is there a way without using macros, for users to simply enter the date? What form do I need to set for users to input the date into the field and avoid having them enter text (e.g using a text box)
|
#15
|
|||
|
|||
"I believe we may not have to use macros in the form/template" What did you have in mind? There is no date picker built-in in versions before 2007. The Insert menu just lets you insert the current date. Other than typing the date, what would there be?
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Calculations using values from date picker controls | Inkarnate | Word | 0 | 06-09-2010 07:16 AM |
Date Function in word? | aligahk06 | Word | 1 | 04-21-2010 06:33 AM |
Word 2007 date and time picker | dmcohio | Word | 2 | 04-09-2010 04:13 AM |
new appointment date always reverts back to today's date | msills | Outlook | 0 | 08-24-2007 08:57 AM |
Imported message date change to today's date | promark | Outlook | 1 | 12-23-2005 07:21 AM |