Change date field to createdate

S

Sammy

Hi,

Yesterday I searched for and finally found a macro that would go through a
folder and change the date fields to createdate fields. Now I can't find
that post! Can anyone help me?

Many thanks
 
S

Sammy

Well, I love this macro and I'm going to keep it for future reference but I
don't think I can search for a date field and replace with a createdate
field, the find and replace dialog didn't allow for that.

Thank you for your help.
 
J

Jean-Guy Marcil

Sammy said:
Well, I love this macro and I'm going to keep it for future reference but I
don't think I can search for a date field and replace with a createdate
field, the find and replace dialog didn't allow for that.

You can add code to toggle the display of field codes in the document, and
then you can use the find/replace to replace field code with other field
code...
 
F

fumei via OfficeKB.com

Dim oField As Field
For Each oField In ActiveDocument.Fields
If oField.Type = 31 Then
oField.Select
Selection.Fields(1).Delete
ActiveDocument.Fields.Add Range:=Selection.Range, Type:=21
End If
Next

will change DATE fields (Type 31) to CREATEDATE fields (Type 21)
Well, I love this macro and I'm going to keep it for future reference but I
don't think I can search for a date field and replace with a createdate
field, the find and replace dialog didn't allow for that.

Thank you for your help.
[quoted text clipped - 4 lines]
 
S

Sammy

That's so smart! Thanks a lot.

Jean-Guy Marcil said:
You can add code to toggle the display of field codes in the document, and
then you can use the find/replace to replace field code with other field
code...
 
S

Sammy

Thank you for your time

fumei via OfficeKB.com said:
Dim oField As Field
For Each oField In ActiveDocument.Fields
If oField.Type = 31 Then
oField.Select
Selection.Fields(1).Delete
ActiveDocument.Fields.Add Range:=Selection.Range, Type:=21
End If
Next

will change DATE fields (Type 31) to CREATEDATE fields (Type 21)
Well, I love this macro and I'm going to keep it for future reference but I
don't think I can search for a date field and replace with a createdate
field, the find and replace dialog didn't allow for that.

Thank you for your help.
[quoted text clipped - 4 lines]
 
G

Graham Mayor

The batch macro you cannot find may have been

Sub BatchFixDates()
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim iFld As Integer
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)

With fDialog
.Title = "Select Folder containing the documents to be modifed and click
OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
PathToUse = fDialog.SelectedItems.Item(1)
If Right(PathToUse, 1) <> "\" Then PathToUse = PathToUse + "\"
End With

If Documents.Count > 0 Then
Documents.Close Savechanges:=wdPromptToSaveChanges
End If
myFile = Dir$(PathToUse & "*.do?")

While myFile <> ""
Set myDoc = Documents.Open(PathToUse & myFile)
ActiveWindow.View.ShowFieldCodes = True
For iFld = ActiveDocument.Fields.Count To 1 Step -1
With ActiveDocument.Fields(iFld)
If .Type = wdFieldDate Then
.Code.Text = Replace(.Code.Text, "DATE", "CREATEDATE")
.Update
End If
End With
Next iFld
ActiveWindow.View.ShowFieldCodes = False
myDoc.Close Savechanges:=wdSaveChanges
myFile = Dir$()
Wend
End Sub


which I have posted a couple of times recently.


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top