Vicki,
This is rough and I hope one of the macor heavy hitters will come along and
clean it up.
I found a macro for doing batch find and replace in a directory. At first I
thought I could just delete the find and replace bit and replace it with a
command to set a docProperty. The problem I faced is that by simply setting
a docProperty Word doesn't regonize the document has changed. I had to set
a docProperty and then trick Word into thinking I made a recognized change
(replaced all spaces with a space ;-) ).
Here it is:
Option Explicit
Public Sub BatchReplaceDocProperties()
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim Expr1 As String
On Error Resume Next
'Close all open documents before beginning
Documents.Close SaveChanges:=wdPromptToSaveChanges
'Define Path (set to meet your needs)
PathToUse = "D:\My Documents\Word Documents\Word Tips\Macros\"
'Solicit User Input (Set prompt and Title to meet your needs)
Expr1 = InputBox("Enter the Document Subject:", "Subject")
'Set the directory and type of file to batch process
myFile = Dir$(PathToUse & "*.doc")
While myFile <> ""
'Open document
Set myDoc = Documents.Open(PathToUse & myFile)
'Trick Word into thinking the document changed
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " "
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
'Set DocProperty
With myDoc
'This next line set the "Title" property to the value of Expr1
'Adapt to meet your needs
.BuiltInDocumentProperties("Title").Value = Expr1
End With
myDoc.Close SaveChanges:=wdSaveChanges
'Process next file in folder
myFile = Dir$()
Wend
End Sub
HTH
If anyone can streamline this code or help me find a better way of saving
the docProperty without having to use the find and replace bit please let me
know.