Printing & header/footer macro - please help!

J

Jen308

Essentially its function is for a Final Copy – printing to letterhead, but
then reinstating the graphic headers and footers so I can email the document
as well. Previously we just printed out a black and white graphic header and
footer using plain paper, but we’ve just had new letterhead made up, so we
need to use that for the final copies. Our document template has colour
graphic headers and footers for when we email the documents, or just print
out a file copy.

Essentially, I need a macro to do the following things:

1. Remove header and footer
2. Print first page to Tray One (letterhead) and remaining pages to Tray Two
3. Reinstate default printer settings (Default Tray)
4. Insert a .jpg back into the header
5. Resize to 21cm width and relevant height
6. Change alignment to Send to Back
7. Position at 0 top and 0 right
8. Insert a .jpg back into the footer
9. Resize to 21cm width and relevant height
10. Change alignment to Send to Back
11. Position at 0 bottom and 0 right
12. Or, instead of steps 4 to 11 - just undo the deletion of the header and
footer.

So far, when I do it, it prints out fine, but when it comes to reinstating
the header and footer, it just sticks both pictures into the header, centred
and not resized. I'm only using the Record Macro function, which obviously
has limitations given some of the buttons are greyed out on the toolbar. I
can read and understand VBA, but I don't know how to code much myself.

Here is the code from the Record Macro:

Sub FinalCopy()
'
' FinalCopy Macro
' Prints first page to letterhead after removing graphic header and footer
'
WordBasic.RemoveHeader
WordBasic.RemoveFooter
With ActiveDocument.Styles(wdStyleNormal).Font
If .NameFarEast = .NameAscii Then
.NameAscii = ""
End If
.NameFarEast = ""
End With
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = CentimetersToPoints(2.54)
.BottomMargin = CentimetersToPoints(2.54)
.LeftMargin = CentimetersToPoints(3.18)
.RightMargin = CentimetersToPoints(2.54)
.Gutter = CentimetersToPoints(0)
.HeaderDistance = CentimetersToPoints(1.25)
.FooterDistance = CentimetersToPoints(1.25)
.PageWidth = CentimetersToPoints(21)
.PageHeight = CentimetersToPoints(29.7)
.FirstPageTray = 258
.OtherPagesTray = 259
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True,
PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
With ActiveDocument.Styles(wdStyleNormal).Font
If .NameFarEast = .NameAscii Then
.NameAscii = ""
End If
.NameFarEast = ""
End With
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = CentimetersToPoints(2.54)
.BottomMargin = CentimetersToPoints(2.54)
.LeftMargin = CentimetersToPoints(3.18)
.RightMargin = CentimetersToPoints(2.54)
.Gutter = CentimetersToPoints(0)
.HeaderDistance = CentimetersToPoints(1.25)
.FooterDistance = CentimetersToPoints(1.25)
.PageWidth = CentimetersToPoints(21)
.PageHeight = CentimetersToPoints(29.7)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.InlineShapes.AddPicture FileName:= _
"T:\Administration\AJ Letterhead Header.jpg", LinkToFile:=False, _
SaveWithDocument:=True
With Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints(-3.18)
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
WordBasic.ViewFooterOnly
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.InlineShapes.AddPicture FileName:= _
"T:\Administration\AJ Letterhead Footer.jpg", LinkToFile:=False, _
SaveWithDocument:=True
With Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints(-3.18)
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
 
J

Jen308

I've also just noticed it deletes all headers and footers, and I only want it
to delete the first page header and footer. So complicated!
 
G

Graham Mayor

Does the first page header contain merely a graphic or does it contain a
graphic and text? If the latter, what paragraph styles are applied to the
text? Are those styles unique to the header?

The reason I ask is that the simple way to do this is to set the graphic
brightness to 100% and the text colour to white for the duration of the
print cycle, then restore it again to its previous settings. By setting them
thus the space they occupied does not change, and being white are not
printed.

For the graphic, to toggle the display you would need something like

Selection.HomeKey wdStory
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
With Selection
.HeaderFooter.Shapes("Picture 1").Select
If .ShapeRange.PictureFormat.Brightness = 1# Then
.ShapeRange.PictureFormat.Brightness = 0.5
Else
.ShapeRange.PictureFormat.Brightness = 1#
End If
End With
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

Jen308

Thanks Graham!

The first page header and footer are both merely graphics, and your solution
sounds like a great one! Would I simply copy the code you have written and
subsitute Footer in place of Header to also change the footer to white?

The code would then be:

Selection.HomeKey wdStory
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
With Selection
..HeaderFooter.Shapes("Picture 1").Select
If .ShapeRange.PictureFormat.Brightness = 1# Then
..ShapeRange.PictureFormat.Brightness = 0.5
Else
..ShapeRange.PictureFormat.Brightness = 1#
End If
End With

Selection.HomeKey wdStory
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
With Selection
..HeaderFooter.Shapes("Picture 2").Select
If .ShapeRange.PictureFormat.Brightness = 1# Then
..ShapeRange.PictureFormat.Brightness = 0.5
Else
..ShapeRange.PictureFormat.Brightness = 1#
End If
End With

Dim OriginalFirstPageSetting As Long, OriginalOtherPagesSetting As Long

With ActiveDocument.PageSetup

OriginalFirstPageSetting = .FirstPageTray
OriginalOtherPagesSetting = .OtherPagesTray

..FirstPageTray = 258
..OtherPagesTray = 259

ActiveDocument.PrintOut

..FirstPageTray = OriginalFirstPageSetting
..OtherPagesTray = OriginalOtherPagesSetting

End With

ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

So what do I replace into Picture1 and Picture2? Because I tried putting in
the file names of the graphic, but I got a run error.
 
J

Jen308

No, wait, that puts the header and footer back in before it prints. I've
also worked out it just needed to be picture 1 (with a space) in order to
work. So now I just need to rearrange the code for it to work properly.
 
G

Graham Mayor

Are the graphics inserted in line or floating with a wrap option?
If you cannot work it out, send a copy of the template to the link on my web
site home page.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

Try the following:

Dim OriginalFirstPageSetting As Long, OriginalOtherPagesSetting, i As Long
Selection.HomeKey wdStory
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
With Selection
For i = 1 To .HeaderFooter.Shapes.Count
.HeaderFooter.Shapes("Picture " & i).Select
.ShapeRange.PictureFormat.Brightness = 1#
Next i
End With
With ActiveDocument.PageSetup
OriginalFirstPageSetting = .FirstPageTray
OriginalOtherPagesSetting = .OtherPagesTray
.FirstPageTray = 258
.OtherPagesTray = 259
ActiveDocument.PrintOut
.FirstPageTray = OriginalFirstPageSetting
.OtherPagesTray = OriginalOtherPagesSetting
End With
With Selection
For i = 1 To .HeaderFooter.Shapes.Count
.HeaderFooter.Shapes("Picture " & i).Select
.ShapeRange.PictureFormat.Brightness = 0.5
Next i
End With
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

You are welcome :)

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


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

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