Share via

Button to insert date

Anonymous
2013-05-23T16:20:49+00:00

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!

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Paul Edstein 82,861 Reputation points Volunteer Moderator
2013-05-23T16:38:06+00:00

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

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2013-05-23T16:53:49+00:00

    Thanks millions!!

    Was this answer helpful?

    0 comments No comments