florismk
10-17-2014, 07:02 AM
Here's a challenge for you all. I've looked everywhere, and it's been bugging me for years that I've never found an answer. If anyone has an answer, you earn my undying gratitude.
We have a print server, where a Custom Form has been defined for our letterhead paper. This Custom Form, named "Company Letterhead" is nothing but A4 paper size with a different name.
We created this Custom Form for one reason only: to link it to the correct (letterhead) paper trays in the server-side printer settings of various printers. The result is that we can select the "Company Letterhead" paper size in a document, and the document will print to letterhead paper on every printer (provided the tray choice is set to "Automatically select"). Since the paper size is stored with the document, this trick ensures that a document prints to letterhead regardless of the user's default printer, and even if he/she switches to a different printer. This way, no one but our support staff needs to remember in which tray the letterhead paper is on each printer.
The "Company Letterhead" Custom Form behaves exactly like a standard paper size, in that it is presented in the Paper Size dropdown in the Ribbon and in Page Setup.
And it is uniquely identified somehow, since it is retained with the document.
What I need is a way to:
A. Set any document to "Company Letterhead" paper from code.
B. Also through code, detect if a document has "Company Letterhead" selected.
The challenge is this: I can't find the paper size choice anywhere.
When I macro-record my actions in setting a document to "Company Letterhead" paper size, and do the same setting a document to A4, the resulting code is identical, setting every property of the PageSetup object (except, oddly enough, .PaperSize) to the same values in either case (code included below).
When I Debug.Print the PageSetup.PaperSize property for an A4 document, it reports wdPaperA4 (7).
When I Debug.Print the same for a "Company Letterhead" document, it reports the same value of 7.
So even though I know for a fact that the "Company Letterhead" paper size choice is stored with the document, I can't for the life of me find that choice in the object model.
Any ideas, anyone?
With Selection.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = CentimetersToPoints(2.54)
.BottomMargin = CentimetersToPoints(2.54)
.LeftMargin = CentimetersToPoints(2.54)
.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 = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
We have a print server, where a Custom Form has been defined for our letterhead paper. This Custom Form, named "Company Letterhead" is nothing but A4 paper size with a different name.
We created this Custom Form for one reason only: to link it to the correct (letterhead) paper trays in the server-side printer settings of various printers. The result is that we can select the "Company Letterhead" paper size in a document, and the document will print to letterhead paper on every printer (provided the tray choice is set to "Automatically select"). Since the paper size is stored with the document, this trick ensures that a document prints to letterhead regardless of the user's default printer, and even if he/she switches to a different printer. This way, no one but our support staff needs to remember in which tray the letterhead paper is on each printer.
The "Company Letterhead" Custom Form behaves exactly like a standard paper size, in that it is presented in the Paper Size dropdown in the Ribbon and in Page Setup.
And it is uniquely identified somehow, since it is retained with the document.
What I need is a way to:
A. Set any document to "Company Letterhead" paper from code.
B. Also through code, detect if a document has "Company Letterhead" selected.
The challenge is this: I can't find the paper size choice anywhere.
When I macro-record my actions in setting a document to "Company Letterhead" paper size, and do the same setting a document to A4, the resulting code is identical, setting every property of the PageSetup object (except, oddly enough, .PaperSize) to the same values in either case (code included below).
When I Debug.Print the PageSetup.PaperSize property for an A4 document, it reports wdPaperA4 (7).
When I Debug.Print the same for a "Company Letterhead" document, it reports the same value of 7.
So even though I know for a fact that the "Company Letterhead" paper size choice is stored with the document, I can't for the life of me find that choice in the object model.
Any ideas, anyone?
With Selection.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = CentimetersToPoints(2.54)
.BottomMargin = CentimetersToPoints(2.54)
.LeftMargin = CentimetersToPoints(2.54)
.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 = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With