Changing more than one saved document at a time


G

Guest

Is it possible to insert headers & footers into ALL word documents already
created? Or atleast all word documents in any particular folder.

Also, is possible to change margins and font in more than one document at
once?
 
Ad

Advertisements

G

Graham Mayor

Chris said:
Is it possible to insert headers & footers into ALL word documents
already created? Or atleast all word documents in any particular
folder.

Also, is possible to change margins and font in more than one
document at once?

In theory these are possible, but much depends on the nature of the
documents and what it is you want to change. If the documents have been
properly formatted using styles, changing the attached template would be a
simpler way to achieve the latter.

As for the former, do the documents (for example) have multiple sections?

For a simple document layout, the basic code would be something along the
lines of the following which opens each document in a selected folder. While
each document is open you can perform whatever changes you want on it - here
the filename is added to the document header, but you can add the code to
add stuff to the footer also and change the body of the document. Time to
investigate how vba works!

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
'Open the document header (this will be the current page header here)
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

'Do what you want in the document header - here the document name is added
With Selection
.EndKey Unit:=wdStory
.Font.Name = "Arial"
.Font.Size = "8"
.ParagraphFormat.Alignment = wdAlignParagraphRight
.TypeText vbCr & ActiveDocument.FullName
End With

'Close the header or switch to the footer
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

'Save ad close the current document
ActiveDocument.Close SaveChanges:=wdSaveChanges
DocList = Dir$()
FirstLoop = False
Loop
Application.ScreenUpdating = True
Exit Sub
err_FolderContents:
MsgBox Err.Description
Exit Sub


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

My web site www.gmayor.com

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

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