Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    May 2009
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Automating a MACROBUTTON field to set date & time - Word doc attached

    I made a Filed stamp that contains two MACROBUTTON fields. The user double-clicks each to set date and time. How can this be automated to always set the current date and time based on the system time? I've tried inserting a current date field but when a saved document is opened later, the date automatically updates to current date, which is not good. A macro calls the stamp with the two MACROBUTTON fields. The form is unlocked at all times. Is there another way to automate this?

    The actual fields are attached in Word 2002 doc.

    Examples
    {MACROBUTTON InsertCurrentDate DATE}
    {MACROBUTTON InsertCurrentTime TIME}
    Attached Files Attached Files

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    If you want the System date/time, why are you using a MACROBUTTON field at all? Word offers a number of fields you can use for this, including:
    DATE displays the current date and/or time
    CREATEDATE displays the date and/or time the document was created or last saved using Save As
    PRINTDATE displays the date and/or time the document was last printed
    SAVEDATE displays the date and/or time the document was last saved
    Any of these can be locked via Ctrl-F11 or converted to text via Ctrl-Shift-F9.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    Star Lounger
    Join Date
    May 2009
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Paul for the excellent suggestions. I now have the date/time field in a text box so user can position it. I want to select the field and run Ctrl-Shift-F9 so that the current date and time never changes when the doc is opened in future. So far, I can't determine the code to select the date/time field because it's inside of a text box. I tried bookmarking the field and can manually Find it but when I record macro to automate that step, the bookmark does not display. Any suggestions?

    Sample stamp attached.

    Thanks again,
    Charlie
    charlie6067
    Attached Files Attached Files

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    The code to unlink it via the bookmark is:
    ActiveDocument.Bookmarks("DateTime").Range.Fields( 1).Unlink
    Without the bookmark, it's a whole lot more complicated:
    Code:
    Dim Shp As Shape, Fld As Field, ShpGrp As Shape
    For Each Shp In ActiveDocument.Shapes
      If Shp.Type = msoGroup Then
        For Each ShpGrp In Shp.GroupItems
          If ShpShpGrp.Type = msoTextBox Then
            With Shp.TextFrame.TextRange
              For Each Fld In .Fields
                If Fld.Type = wdFieldDate Then
                  Fld.Unlink
                  Exit Sub
                End If
              Next
            End With
          End If
        Next
      ElseIf Shp.Type = msoTextBox Then
        With Shp.TextFrame.TextRange
          For Each Fld In .Fields
            If Fld.Type = wdFieldDate Then
              Fld.Unlink
              Exit Sub
            End If
          Next
        End With
      End If
    Next
    Last edited by macropod; 2012-09-18 at 18:08.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •