Button to insert date

Context: I have created a tab with various commands groups, mostly from macros. My objective are to achieve standardization of the content input and that novice users can fill a word document matrix with little or no knowledge of Word and tables. The date must be that of the day of the input of a row, not that of the document creation.

The predefined formats (Insert tab, text group, date and time) are not suitable so I used the field Date when I recorded the macro. I tried to do Ctrl+Shift+F9 but the macro did not record that command.

What code do i need to add to my VBA to insure that the date is "unfielded" once created?  I tried the following but it does not work...

====================
Sub InsérerDate()
'
' InsérerDate Macro
'
'
    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
        "DATE  \@ ""dd/MM"" ", PreserveFormatting:=True
    Selection.Fields.Unlink
End Sub
=====================

Thank you!
Answer
Answer

Instead of trying to create, then unlink a field, insert the date as text directly:

 

Sub InsérerDate()
Selection.InsertAfter Format(Date, "dd/MM")
End Sub

Cheers
Paul Edstein
(Fmr MS MVP - Word)

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 5, 2021 Views 314 Applies to: