Excel PrintOut using VBA (Visual Basic for Applications) Example

Excel PrintOut using VBA (Visual Basic for Applications) Example

PrintOut

Method prints specific range, print area, sheet or entire Excel workbook based on expression attached to PrintOut method. Let’s put some VBA code to examine various ways to Print.

Print Area

Set a Print Area and give name to it by default Excel adds print area name as “PrintArea“. A sheet can have only one Print Area which can be verified under Name Manager.

Code example

Public Function PrintPrintAreaExample(oPrintAreaName As String) As Boolean
    PrintPrintAreaExample = False
    Worksheets(oSheetName).Range(oPrintAreaName).PrintOut
    PrintPrintAreaExample = True
End Function

Print Sheet

Public Function PrintSheetExample(oSheetName As String) As Boolean
    PrintSheetExample = False
    Worksheets(oSheetName).PrintOut
    PrintSheetExample = True
End Function

Print Range

Public Function PrintRangeExample(oPrintRange As Range) As Boolean
    PrintRangeExample = False
    oPrintRange.PrintOut
    PrintRangeExample = True
End Function

Print Workbook

Public Function PrintWorkbookExample(oWorkbook As Workbook) As Boolean
    PrintWorkbookExample = False
    oWorkbook.PrintOut
    PrintWorkbookExample = True
End Function

Please leave your comments or queries under comment section also please do subscribe to our blogs to keep your self upto date.

Leave a Reply

Your email address will not be published.