none
SEARCH FOR CREATEDATE AND UPDATE TO DATE FIELD THEN TURN INTO TEXT RRS feed

  • Question

  • I would like to write a macro to search for all createdate fields {CREATEDATE \@"d MMMM yyyy"} in a word 2010 document then UPDATE this to today's date {DATE \@"d MMMM yyyy"}  as text. I would appreciate if someone can help as I am a macro novice. 

    Thanks in advance


    Tuesday, July 16, 2013 12:11 PM

Answers

  • Hi Amy

    If you change CreateDate to Date, then update, the field should behave the same as a Date field inserted from the Ribbon (as long as you activate the option to update automatically). The fields haven't changed from those in 2003, just the interface used to access them. If you press Alt+F9 you toggle on the display of the field codes.

    As soon as you unlink the field you get "plain old text" - again, the same behavior as in Word 2003.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Amy12 Friday, July 19, 2013 1:57 PM
    Friday, July 19, 2013 1:23 PM
    Moderator

All replies

  • The following macro does as you request: replaces CreateDate with Date throughout the main part of the document.

    Sub ChangeFieldNames()
        Dim rng As word.Range
        Set rng = ActiveDocument.Content
        rng.TextRetrievalMode.IncludeFieldCodes = True
        With rng.Find
            .ClearFormatting
            .Text = "CreateDate"
            .Replacement.Text = "Date"
            .Execute Replace:=wdReplaceAll
        End With
        ActiveDocument.Fields.Update
    End Sub
    


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, July 16, 2013 2:22 PM
    Moderator
  • Thanks Cindy for your prompt assistance.

    It does work perfectly to change the CreateDate to Date and update to today's date but it still have the field code behind. How do I remove the field code and turn it into just text?

    Tuesday, July 16, 2013 11:48 PM
  • Hi Amy

    Ah, I wasn't sure if you meant that literally, or just that you didn't want to see a field code.

    After ActiveDocument.Fields.Update add the line:

    ActiveDocument.Fields.Unlink


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, July 17, 2013 12:53 PM
    Moderator
  • Thanks again Cindy.

    It works perfectly. I would like to turn into text (or unlink as you recommend) so this date won't be further automatically updated next time when the document is opened.

    Many thanks for your help.


    • Edited by Amy12 Wednesday, July 17, 2013 1:58 PM Mistake
    • Marked as answer by Amy12 Friday, July 19, 2013 12:14 PM
    • Unmarked as answer by Cindy Meister MVPModerator Friday, July 19, 2013 1:20 PM
    Wednesday, July 17, 2013 1:57 PM
  • Hi Cindy

    I still have another query: if I changed 'createdate' to 'date' this way, will the 'date' (today's date) behave exactly the same way as the Date  & Time that I insert from Word 2010's ribbon of a document? (The createdate date was originally created in Word 2003 by using Insert Field).

    Thanks again

    Friday, July 19, 2013 12:14 PM
  • Hi Amy

    If you change CreateDate to Date, then update, the field should behave the same as a Date field inserted from the Ribbon (as long as you activate the option to update automatically). The fields haven't changed from those in 2003, just the interface used to access them. If you press Alt+F9 you toggle on the display of the field codes.

    As soon as you unlink the field you get "plain old text" - again, the same behavior as in Word 2003.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Amy12 Friday, July 19, 2013 1:57 PM
    Friday, July 19, 2013 1:23 PM
    Moderator
  • Thanks Cindy again for your prompt response. I greatly appreciate it.
    Friday, July 19, 2013 2:01 PM