PDA

View Full Version : Paste Image From File Into Footer



juan4412
07-11-2015, 08:09 PM
I need word vba to take an image from file and insert it into the footer of each sheet in a word doc. How can this be done?

gmayor
07-11-2015, 09:47 PM
The following will insert a named image at the start of every footer of the document



Dim oSection As Section
Dim oFooter As HeaderFooter
Dim oRng As Range
For Each oSection In ActiveDocument.Sections
For Each oFooter In oSection.Footers
If oFooter.Exists Then
Set oRng = oFooter.Range
oRng.Collapse 1
oRng.InlineShapes.AddPicture _
Filename:="C:\Path\ImageName.jpg", _
LinkToFile:=False, _
SaveWithDocument:=True
End If
Next oFooter
Next oSection

gmaxey
07-12-2015, 06:16 AM
I believe the code will work with and without the "If oFooter.Exists Then ... End If" lines. If you think you would every change the page layout to different first page or different odd/even after running the code and "really" want the image to be in all footers then take it out.

The footers already exists. Exists in this case only means are the being used in page layout.