none
Inserting a date and time function RRS feed

  • Question

  • When inserting a date and time function to different headings to exemplify the section update the whole document will be updated when re-opened.  Using multiple time stamps in one document becomes inconclusive to the use of date and time stamps.

    My recommendation, set the provisions and indexing to date and time stamps for multiple use in one document.  Otherwise, what type of API code or other code could I use in a Word document to enforce multiple use of date and time stamps.

    Joe

    Saturday, March 12, 2016 9:05 AM

Answers

  • correct me if I have any misunderstandings on your question, you could insert date time stamp into header

    If you re-read icvillajoe's post you'll see he is working with headings, not headers...

    Furthermore, 'ActiveDocument.Fields.Add rng' does nothing meaningful - it just inserts an unnecessary empty field into the header. To insert a fixed date & time into a heading via macro, all the OP needs is a single line of code like:

    Selection.InsertBefore Format(Now(), "MMMM D, YYYY h:mm AM/PM")


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by David_JunFeng Monday, March 21, 2016 2:21 PM
    Monday, March 14, 2016 10:19 AM

All replies

  • Alt-Shift-D and Alt-Shift-T insert date & time fields. These are meant to update whenever the document is re-opened. If you don't want that behaviour, you can unlink or lock the fields after inserting them (Ctrl-Shift-F9, or Ctrl-F11, respectively) Alternatively, you could use a macro to input a date & time stamp in whatever date & time format you require.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Saturday, March 12, 2016 10:19 AM
  • Hi, icvillajoe

    According to your description, please correct me if I have any misunderstandings on your question, you could insert date time stamp into header, refer to below code:
    Dim rng As Range
    Set rng = ActiveDocument.Sections.First.Headers(wdHeaderFooterPrimary).Range
    rng.Text = Format(Now(), "MMMM dd, yyyy hh:mm AM/PM") & vbTab
    rng.Collapse wdCollapseEnd
    ActiveDocument.Fields.Add rng

    • Marked as answer by David_JunFeng Monday, March 21, 2016 2:21 PM
    • Unmarked as answer by David_JunFeng Wednesday, March 23, 2016 8:15 AM
    Monday, March 14, 2016 9:16 AM
  • correct me if I have any misunderstandings on your question, you could insert date time stamp into header

    If you re-read icvillajoe's post you'll see he is working with headings, not headers...

    Furthermore, 'ActiveDocument.Fields.Add rng' does nothing meaningful - it just inserts an unnecessary empty field into the header. To insert a fixed date & time into a heading via macro, all the OP needs is a single line of code like:

    Selection.InsertBefore Format(Now(), "MMMM D, YYYY h:mm AM/PM")


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by David_JunFeng Monday, March 21, 2016 2:21 PM
    Monday, March 14, 2016 10:19 AM
  • Thank you for the post.  To get the content correctly I must activate macro, add the selection into the heading and define each heading as required. When a heading section is updated, I select update the time and date and the heading section date and time is updated.  However, using any time and date function with MS Word 2016, the function updates the the date and time automatically when reopening the document.  Thus, date and time functions become useless with the automatic field update to a section or document.  What macro coding would prevent the 'ActiveDcoumentField' from giving erroneous points or does your other post suffice the question

    Alt-Shift-D and Alt-Shift-T insert date & time fields. These are meant to update whenever the document is re-opened. If you don't want that behaviour, you can unlink or lock the fields after inserting them (Ctrl-Shift-F9, or Ctrl-F11, respectively) Alternatively, you could use a macro to input a date & time stamp in whatever date & time format you require.


     

    Joe icvillajoe

    Tuesday, March 22, 2016 11:55 PM
  • using any time and date function with MS Word 2016, the function updates the the date and time automatically when reopening the document.  Thus, date and time functions become useless with the automatic field update to a section or document.

    The fields' behaviour may not meet your needs, but they are doing what they are meant to do and, as such, meet the needs of many other users. Useless in not how I'd characterize it.

    If you add a macro like the following to your document's template and assign a keyboard shortcut to it, you can quickly insert a fixed date & time wherever you want without the need to go through the 'activation' steps.

    Sub AddDateTime()
    Selection.InsertBefore Format(Now(), "MMMM D, YYYY h:mm AM/PM")
    End Sub

    For PC macro installation & usage instructions, including the assignment of keyboard shortcuts, see: http://www.gmayor.com/installing_macro.htm


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, March 23, 2016 12:35 AM
  • Thanks again.

    As you said, "useless is not how I'd characterize it."  I see your point and shall rephrase - the time and date function does not work for me in most of the business publications / reports I edit and outline.  Adding date and time to heading sections is an added benefit to prevent ambiguous matters.  I thank you for the code to date and time function, that will help.  Also the function keys work well too.

    Cheers back to you

    Joe, icvillajoe


    Joe icvillajoe

    Wednesday, March 23, 2016 1:00 AM