|
|
|
|
|
|
Word
|
Change Header in a Batch of Files
|
|
Ease of Use
|
Intermediate
|
Version tested with
|
2000
|
Submitted by:
|
R_Rajesh
|
Description:
|
Change a logo or other graphic, or change the entire header in a folder full of Word documents all at once.
|
Discussion:
|
Maybe your company's logo has changed and you need to replace the logo in all the documents in a folder.
The first procedure (sub) below opens all the Word documents in a directory. In each file, it replaces the first object (shape/graphic) in the header with the contents of the clipboard.
The second procedure (sub) below deletes the entire header and replaces it with the contents of the clipboard.
|
Code:
|
instructions for use
|
Sub ReplaceJustLogo()
Dim wrd As Word.Application
Set wrd = CreateObject("word.application")
wrd.Visible = True
AppActivate wrd.Name
fName = Dir("C:\temp\*.doc")
Do While (fName <> "")
With wrd
.Documents.Open ("C:\Temp\" & fName)
If .ActiveWindow.View.SplitSpecial = wdPaneNone Then
.ActiveWindow.ActivePane.View.Type = wdPrintView
Else
.ActiveWindow.View.Type = wdPrintView
End If
.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
.Selection.WholeStory
If .Selection.InlineShapes.Count <> 0 Then .Selection.InlineShapes(1).Delete
.Selection.Paste
.ActiveDocument.Save
.ActiveDocument.Close
End With
fName = Dir
Loop
Set wd = Nothing
End Sub
Sub ReplaceEntireHdr()
Dim wrd As Word.Application
Set wrd = CreateObject("word.application")
wrd.Visible = True
AppActivate wrd.Name
fName = Dir("C:\temp\*.doc")
Do While (fName <> "")
With wrd
.Documents.Open ("C:\Temp\" & fName)
If .ActiveWindow.View.SplitSpecial = wdPaneNone Then
.ActiveWindow.ActivePane.View.Type = wdPrintView
Else
.ActiveWindow.View.Type = wdPrintView
End If
.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
.Selection.WholeStory
.Selection.Paste
.ActiveDocument.Save
.ActiveDocument.Close
End With
fName = Dir
Loop
Set wrd = Nothing
End Sub
|
How to use:
|
- Copy the appropriate code above for your needs.
- Open a blank Word document.
- Hit Alt+F11 to open the Visual Basic Editor.
- From the menu, choose Insert-Module.
- Paste the code into the code window at right.
- Change the paths in the code to work for your specific needs.
- Close the VBE and save the file if desired.
|
Test the code:
|
- Copy either a logo or entire header, depending on which code you will run. The object will be copied to the clipboard.
- Hit Tools-Macro-Macros and double-click the appropriate macro: either ReplaceJustLogo or ReplaceEntireHeader.
|
Sample File:
|
No Attachment
|
Approved by Anne Troy
|
This entry has been viewed 143 times.
|
|