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
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