- Joined
- May 6, 2014
- Messages
- 2
- Reaction score
- 0
Hi all,
I have already created a macro which puts an image as the header and footer on a Word 2010 document. This all works fine but when you add another page, the header and footer automatically gets added to the subsequent pages.
I only want the header and footer to be on the first page of the document no matter how many more pages there are after that. Below is the macro I have created:
Sub BucklesTemplate()
'
' BucklesTemplate Macro
' Macro coded 01/04/2014 by Rajan Kandola
'
'switch to header
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
'add logo to header
With ActiveDocument.Shapes.AddPicture(Anchor:=Selection.Range, _
FileName:="C:\Users\kandolar.BUCKLEMELLOWS\Desktop\Buckles Letter Format\logo.jpg", _
LinkToFile:=False, SaveWithDocument:=True)
.WrapFormat.Type = 3
.ZOrder 4
.LockAspectRatio = False
End With
'select the last item in shapes list - should be logo that was just added
Selection.HeaderFooter.Shapes(Selection.HeaderFooter.Shapes.Count).Select
'set relative vertical position to Page So that it will stay in the header
Selection.ShapeRange.Top = PixelsToPoints(0)
'reposition the logo - to test I moved them horizontally to about the center of the page
Selection.ShapeRange.Left = PixelsToPoints(210)
'switch to footer
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
'add banner to footer
With ActiveDocument.Shapes.AddPicture(Anchor:=Selection.Range, _
FileName:="C:\Users\kandolar.BUCKLEMELLOWS\Desktop\Buckles Letter Format\disclaimer+btmBanner.jpg", _
LinkToFile:=False, SaveWithDocument:=True)
.WrapFormat.Type = 3
.ZOrder 4
.LockAspectRatio = False
'change size of footer image
.Height = InchesToPoints(1.3)
.Width = InchesToPoints(8.31)
'make footer image relative to margin
.WrapFormat.Type = wdRelativeVerticalPositionMargin
End With
'select the last item in shapes list - should be logo that was just added
Selection.HeaderFooter.Shapes(Selection.HeaderFooter.Shapes.Count).Select
'set relative vertical position to Page So that it will stay in the footer
Selection.ShapeRange.Top = PixelsToPoints(980)
'reposition the logo - to test I moved them horizontally to about the center of the page
Selection.ShapeRange.Left = PixelsToPoints(0)
'switch back to main document
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
I'm pretty sure it's probably only 1 line of simple code that I'm missing but I just can't work it out. As this is my first post I hope the info I've given is okay!
Thanks,
Rajan
I have already created a macro which puts an image as the header and footer on a Word 2010 document. This all works fine but when you add another page, the header and footer automatically gets added to the subsequent pages.
I only want the header and footer to be on the first page of the document no matter how many more pages there are after that. Below is the macro I have created:
Sub BucklesTemplate()
'
' BucklesTemplate Macro
' Macro coded 01/04/2014 by Rajan Kandola
'
'switch to header
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
'add logo to header
With ActiveDocument.Shapes.AddPicture(Anchor:=Selection.Range, _
FileName:="C:\Users\kandolar.BUCKLEMELLOWS\Desktop\Buckles Letter Format\logo.jpg", _
LinkToFile:=False, SaveWithDocument:=True)
.WrapFormat.Type = 3
.ZOrder 4
.LockAspectRatio = False
End With
'select the last item in shapes list - should be logo that was just added
Selection.HeaderFooter.Shapes(Selection.HeaderFooter.Shapes.Count).Select
'set relative vertical position to Page So that it will stay in the header
Selection.ShapeRange.Top = PixelsToPoints(0)
'reposition the logo - to test I moved them horizontally to about the center of the page
Selection.ShapeRange.Left = PixelsToPoints(210)
'switch to footer
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
'add banner to footer
With ActiveDocument.Shapes.AddPicture(Anchor:=Selection.Range, _
FileName:="C:\Users\kandolar.BUCKLEMELLOWS\Desktop\Buckles Letter Format\disclaimer+btmBanner.jpg", _
LinkToFile:=False, SaveWithDocument:=True)
.WrapFormat.Type = 3
.ZOrder 4
.LockAspectRatio = False
'change size of footer image
.Height = InchesToPoints(1.3)
.Width = InchesToPoints(8.31)
'make footer image relative to margin
.WrapFormat.Type = wdRelativeVerticalPositionMargin
End With
'select the last item in shapes list - should be logo that was just added
Selection.HeaderFooter.Shapes(Selection.HeaderFooter.Shapes.Count).Select
'set relative vertical position to Page So that it will stay in the footer
Selection.ShapeRange.Top = PixelsToPoints(980)
'reposition the logo - to test I moved them horizontally to about the center of the page
Selection.ShapeRange.Left = PixelsToPoints(0)
'switch back to main document
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
I'm pretty sure it's probably only 1 line of simple code that I'm missing but I just can't work it out. As this is my first post I hope the info I've given is okay!
Thanks,
Rajan