BATCH insert header & footer

G

Guest

Hi,

I have several ".doc" files (Word 2000) that I need to print off, with the
filename and path (path too, ideally, but just filename will suffice if it
has to).

I am aware of how to open a single file and add in a header with the path
and file name, but I want to do this to several hundred files as quickly as
possible.

Can you help please?

Regards, Neil
 
G

Graham Mayor

The following macro will print all the documents in a chosen folder with the
filename and path added in the header, right aligned in 8 point Arial

The changes are not saved to the documents - Test with a small sample to
ensure it does what you want.

Sub PrintWithFileNames()
On Error GoTo err_FolderContents
Dim FirstLoop As Boolean
Dim DocList As String
Dim DocDir As String

With Dialogs(wdDialogCopyFile)
If .Display <> 0 Then
DocDir = .Directory
Else
MsgBox "Cancelled by User"
Exit Sub
End If
End With
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
Application.ScreenUpdating = False
FirstLoop = True
If Left(DocDir, 1) = Chr(34) Then
DocDir = Mid(DocDir, 2, Len(DocDir) - 2)
End If
DocList = Dir$(DocDir & "*.doc")
Do While DocList <> ""
Documents.Open DocList
Selection.EndKey Unit:=wdStory
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
With Selection
.EndKey Unit:=wdStory
.Font.Name = "Arial"
.Font.Size = "8"
.ParagraphFormat.Alignment = wdAlignParagraphRight
.TypeText vbCr & ActiveDocument.FullName
End With
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
ActiveDocument.PrintOut
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
DocList = Dir$()
FirstLoop = False
Loop
Application.ScreenUpdating = True
Exit Sub
err_FolderContents:
MsgBox Err.Description
Exit Sub
End Sub

See http://www.gmayor.com/installing_macro.htm
 
G

Guest

Perfect!

You Graham, are a star!

Thanks so much, this has really saved me hours and hours!

All the best,

Neil.
 

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