Thread: [Solved] word 2003 date picker
View Single Post
 
Old 09-27-2010, 12:49 PM
Kimberly Kimberly is offline Windows 7 Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Posts: 517
Kimberly is on a distinguished road
Default

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
Reply With Quote