views:

17

answers:

1

Hi everyone,

I'm working on a Word document which has a table on each page. Each table contains several occurrences of the word "Datum". By doubleclicking this word "Datum", this word should be replaced with the system date. And this date should be "frozen", i.e. it mustn't adapt itself when opening the document on a different day.

Is there anyone who can help me out with the code for this?

Thanks a lot!

A: 

You can do that using a macro button field:

  • Press Ctrl + F9 to create a new field
  • Enter the following text within the curly braces:

    MACROBUTTON  InsertDateTime Datum
    

    The result will look as follows:

    { MACROBUTTON  InsertDateTime Datum }
    
  • Press Alt + F9 to toggle field code display

This will show Words built-in Insert Date dialog. If you don't want to display the dialog you can replace InsertDateTime with the name of a custom VBA macro, e.g. MyModule.MyInsertDate. This macro would replace the field with the current date:

Public Sub Test()
    Selection.Text = Now
End Sub
0xA3