![]() |
|
#1
|
|||
|
|||
![]() Hello, I have a content control date picker in word document. How to set the date picker to show current date on opening the document. I am looking for a vba code to achieve this, as there are other content control dependent on date picker in my document. Thank you. |
#2
|
||||
|
||||
![]()
Add the following code to the ThisDocument module of the document. Name the date content control and replace "Today's Date" in the code with the Title of the content control. Save as macro enabled document.
However, why not use instead a bookmarked date field which will always show the current date and doesn't need the macro? Code:
Option Explicit Private Sub Document_Open() Dim objCC As ContentControl Dim objDate As Date For Each objCC In ActiveDocument.ContentControls If objCC.Title = "Today's Date" Then objDate = Date objCC.Range.Text = objDate Exit For End If Next objCC End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
![]()
For those looking for a non-VBA method. I have used this method successfully.
1- Insert a new date picker content control from the Developer Tab. 2- Select the Design Mode in the Developer Tab. 3- Delete the "Click here to enter a date." default text. 4- From the Insert tab, select Insert Date and Time. 5- Select the style of the default today's date style and check the Update automatically box. 6- Right click the date picker content control and select properties. 7- Select the matching date style for the date picker. 8- Turn off the Design Mode in the Developer Tab. Will display today's date by default instead of the content control's creation date. |
![]() |
Tags |
content control events, date pickers, vba code |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
legaleagle | Word | 15 | 01-07-2015 06:58 PM |
Possible to link a date picker to another date picker? | tubbz | Word | 0 | 05-07-2014 01:23 PM |
Date Picker Control | Karen615 | Word | 3 | 04-02-2014 02:57 PM |
![]() |
Erbwon | Word | 6 | 11-12-2012 06:17 PM |
![]() |
ketanco | Project | 1 | 02-08-2012 02:20 PM |