Question on using VBA to print. I have a data table, and I want to generate reports from it. There will be a worksheet with buttons to run the various reports. Behind those buttons will be macros that filter the table, sort the results, and send the user to the print preview where they can decide to go ahead with the print or cancel out. Regardless of what they choose, the macro will (after the print or the cancel) return them to the worksheet with the table and will undo the sorting and filtering so it is in its normal state.
Question: I have code to set up the printed sheets with headers and footers and the reports will have a different title in the header. The code is:
[pre]
[/pre]
The question is: do I need ALL of this in each macro? I'm thinking if I don't, and only include, say, the lines that set up the header and footer text, if the user runs some other print operation in between running my macros, it could UN-DO what this code does for some of the other things (like for example page orientation). Then when they run my macros again, they'll get a portrait orientation when they are expecting landscape.
Any words of wisdom on this?
Question: I have code to set up the printed sheets with headers and footers and the reports will have a different title in the header. The code is:
[pre]
Code:
With ActiveSheet.PageSetup
.LeftHeader = "MAPD LESSONS LEARNED"
.CenterHeader = "MASTER TABLE (All Rows), Sorted by Item Number"
.RightHeader = "Printed on: &D"
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = "Page &P of &N"
.LeftMargin = Application.InchesToPoints(0.7)
.RightMargin = Application.InchesToPoints(0.7)
.TopMargin = Application.InchesToPoints(0.75)
.BottomMargin = Application.InchesToPoints(0.75)
.HeaderMargin = Application.InchesToPoints(0.3)
.FooterMargin = Application.InchesToPoints(0.3)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = False
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
The question is: do I need ALL of this in each macro? I'm thinking if I don't, and only include, say, the lines that set up the header and footer text, if the user runs some other print operation in between running my macros, it could UN-DO what this code does for some of the other things (like for example page orientation). Then when they run my macros again, they'll get a portrait orientation when they are expecting landscape.
Any words of wisdom on this?