Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Youngstown, Ohio, USA
    Posts
    705
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Convert date field to fixed (2000 SR1)

    I have a couple of document templates saved that contain date fields. It is nice to have the current date automatically inserted whenever the template is opened up, but it causes some problems when the saved document is later opened and the date auto-updates when it isn't desired. Is there any snippet of code that could be added to the "Save As" routine that would automatically convert the date field to fixed text when the template is saved as a document?

  2. #2
    Lounger
    Join Date
    May 2001
    Location
    the Netherlands
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Convert date field to fixed (2000 SR1)

    Couldn't you use the CreateDate field?

    (Does cause a problem though, if you insert the document in another document with a later date created stamp.)

    If you know the index number of the field something like ActiveDocument.Fields(1).Unlink perhaps.

    Ingrid

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Convert date field to fixed (2000 SR1)

    This is a fun one. It's not too difficult to check all the fields in the body (main story) to see if any are DATE fields, and if so, unlink them. It's a bit trickier to answer the question, "am I template or am I document."

    On the first point, how about something like this:
    <pre>If ActiveDocument.StoryRanges(wdMainTextStory).Fields .Count > 0 Then
    Dim flds As Fields, intCounter As Integer
    Set flds = ActiveDocument.StoryRanges(wdMainTextStory).Fields
    For intCounter = flds.Count To 1 Step -1
    If flds(intCounter).Type = wdFieldDate Then
    flds(intCounter).Unlink
    End If
    Next
    Set flds = Nothing
    End If</pre>

    On the second point, my usual method is crude and I think better methods have been posted in the Lounge, here or in the VBA area.

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Convert date field to fixed (2000 SR1)

    Hi David:
    What if you did this? Have your template with a {Date} field. Have an AutoNew macro that goes to the field, selects it, locks it, & then puts the cursor where you want to start typing. Then you always have a current date when you start a document & if it takes several days to create & you want a later date on it, unlock, update, & relock the field. I use something like this for all my letters.

    Cheers,

  5. #5
    New Lounger
    Join Date
    Sep 2001
    Location
    Manchester, Lancashire, England
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Convert date field to fixed (2000 SR1)

    This response is rather late. I already have a couple of templates which do this, but it is so long since I set them up, I could not remember how, so I came here to refresh my memory.

    My solution is also macro-based, as some of the others, but it is a lot shorter:

    Create a bookmark in your document called "Date" where you want the date to go, then create an AutoNew macro with the following code:

    Selection.GoTo What:=wdGoToBookmark, Name:="date"
    Selection.InsertDateTime DateTimeFormat:="d MMMM, yyyy", InsertAsField:=False

    This will insert the current date into your document when you create it as text, so it cannot be updated.

    Hope this helps,

    Julian

Posting Permissions

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