Printing
These macro codes will
help you to automate some printing tasks which can further save you a ton of
time.
Print Comments
Use this macro to
activate settings to print cell comments in
the end of the page. Let’s say you have 10 pages to print, after using this
code you will get all the comments on 11th last page.
Sub printComments()
With ActiveSheet.PageSetup
.printComments= xlPrintSheetEnd
End With
End Sub
Print Narrow Margin
Use this VBA code to take a print with a narrow margin. When you
run this macro it will automatically change margins to narrow.
Sub printNarrowMargin()
With ActiveSheet.PageSetup
.LeftMargin= Application
.InchesToPoints(0.25)
.RightMargin= Application.InchesToPoints(0.25)
.TopMargin= Application.InchesToPoints(0.75)
.BottomMargin= Application.InchesToPoints(0.75)
.HeaderMargin= Application.InchesToPoints(0.3)
.FooterMargin= Application.InchesToPoints(0.3)
End With
ActiveWindow.SelectedSheets.PrintOutCopies:=1, Collate:=True,
IgnorePrintAreas:=False End Sub
Print Selection
This code will help you print selected range. You don't need to
go to printing options and set printing range. Just select a range and run this
code.
Sub printSelection()
Selection.PrintOutCopies:=1, Collate:=True
End Sub
Print Custom Pages
Instead of using the setting from print options you can use this
code to print custom page range. Let’s say you want to print pages from 5 to
10. You just need to run this VBA code and enter start page and end page.
Sub printCustomSelection()
Dim startpageAs Integer
Dim endpageAs Integer
startpage= InputBox("Please Enter Start Page number.",
"Enter Value")
If Not WorksheetFunction.IsNumber(startpage) Then
MsgBox"Invalid Start Page number. Please try again.",
"Error"
Exit Sub
End If
endpage= InputBox("Please Enter End Page number.",
"Enter Value")
If Not WorksheetFunction.IsNumber(endpage) Then
MsgBox"Invalid End Page number. Please try again.",
"Error"
Exit Sub
End If
Selection.PrintOutFrom:=startpage, To:=endpage, Copies:=1,
Collate:=True
End Sub
No comments:
Post a Comment