It is possible to do this using a batch processing macro. The bigger problem
would occur if the documents were randomly created using a variety of
templates and there was content already in the document header and if there
was more than one header in the document, in which case where would you want
to put the filename in relation to any headers already present? The
following macro contains the basic code. It takes no account of existing
headers nor will work with protected documents. It simply puts the filename
at the end of the first page header. *Use on copies of the documents*.
Sub BatchFileNamesinHeader()
On Error GoTo err_FolderContents
Dim myFile As String
Dim DocList As String
Dim DocDir As String
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)
Selection.HomeKey Unit:=wdStory
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
With Selection
.EndKey Unit:=wdStory
.Font.name = "Arial"
.Font.Size = "8"
.ParagraphFormat.Alignment = wdAlignParagraphRight
.TypeText ActiveDocument.FullName
End With
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
myDoc.Close SaveChanges:=wdSaveChanges
myFile = Dir$()
Wend
Application.ScreenUpdating = True
Exit Sub
err_FolderContents:
MsgBox Err.Description
Exit Sub
End Sub
http://www.gmayor.com/installing_macro.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>