Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have multiple word documents that have a date field code displaying the current date. I need a way to modify each document so that it shows the CreateDate field instead of Date.

The format for each field is currently DATE \@ "dd MMMM yyyy" on each of the documents, but I would like it changed to CREATEDATE \@ "dd MMMM yyyy".

Is there anyway I can automate this for multiple documents, instead of having to go into each one separately?

If it helps, there is only 1 date field in all of the documents and they are in .doc format

Thanks in advance!

share|improve this question
add comment

2 Answers

Here is the macro as short as possible.
It will change all Date fields to CreateDate fields within all open Word documents.

  • open all Word documents you want to change
  • pick a random one and press ALT+F11
  • insert the code below into ThisDocument
  • close your VBA editor and press ALT+F8 and ececute the macro

    Sub replacedate()
    For Each mydoc In Documents
        For Each myfield In mydoc.Fields
            If myfield.Code Like " DATE  \@ ""dd MMMM yyyy""*" Then
                 myfield.Code.Text = " CREATEDATE  \@ ""dd MMMM yyyy""  \* MERGEFORMAT "
            End If
        Next
    Next
    End Sub
    

Since this is a Q&A site, I describe the code. That way it may be helpful for others who can easily adapt and customize the code.

  1. starts and ends a macro (subroutine)
  2. loops through all open Word documents
  3. loops through all available fields within that particular document
  4. condition to check if the current field is a Date field
  5. if yes, the field formula will be changed to CreateDate
  6. belongs to line 4 and closes the IF-condition
  7. belongs to line 3 and closes the loop for fields
  8. belongs to line 2 and closes the loop for documents
  9. belongs to line 1 and closes the whole routine
share|improve this answer
add comment

In the past, I have used the VBA Find & Replace add-in to update multiple documents. The claim is;

VBA Find and Replace© provides a method for finding and replacing text anywhere in a document

You will have to investigate whether the "anywhere" includes field codes.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.