{"id":12200,"date":"2014-06-15T07:51:35","date_gmt":"2014-06-15T07:51:35","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/wp\/?p=3795"},"modified":"2017-07-19T06:15:33","modified_gmt":"2017-07-19T06:15:33","slug":"excel-macro-to-print","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2014\/06\/excel-macro-to-print\/","title":{"rendered":"Excel Macro : Excel VBA code to Print the Sheet"},"content":{"rendered":"
Hello Friends,<\/p>\n
Hope you are doing well !! Thought of sharing a small VBA code to help you writing a code to print the Workbook, Worksheet, Cell Range, Chart etc. .PrintOut ()<\/i><\/strong> Method is used to print any Excel Object.<\/p>\n YourObj.PrintOut(From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, IgnorePrintAreas)<\/i><\/p>\n Based on above explanation and Syntax we will see examples of printing the Workbook, sheets, charts etc.<\/p>\n In this set of examples, I am using all default options to print. This means I am not providing any other parameter to the method .PrintOut<\/strong><\/p>\n Hello Friends, Hope you are doing well !! Thought of sharing a small VBA code to help you writing a code to print the Workbook, Worksheet, Cell Range, Chart etc. .PrintOut () Method is used to print any Excel Object. Syntax of .PrintOut Method YourObj.PrintOut(From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, IgnorePrintAreas) Where: YourObj […]<\/p>\n","protected":false},"author":45,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[1246,1675],"tags":[],"class_list":["post-12200","post","type-post","status-publish","format-standard","hentry","category-macro","category-excel-macro-for-beginners"],"yoast_head":"\nSyntax of .PrintOut Method<\/h1>\n
Where:<\/h2>\n
\n\n
\n \n \n
Examples to Print Excel:<\/h1>\n
Example 1: VBA Statements to Print Objects with Default Options<\/h1>\n
1. VBA code to print ActiveWorkbook<\/h1>\n
\r\nFunction PrintActiveWorkbook()\r\n ActiveWorkbook.PrintOut\r\nEnd Function\r\n\r\n<\/code><\/pre>\n
2. VBA code to print Active Sheet<\/h1>\n
\r\nFunction PrintActiveSheet()\r\n ActiveSheet.PrintOut\r\nEnd Function\r\n\r\n<\/code><\/pre>\n
3. VBA code to print all WorkSheets<\/h1>\n
\r\nFunction PrintAllWorkSheets()\r\n WorkSheets.PrintOut\r\nEnd Function\r\n\r\n<\/code><\/pre>\n
4. VBA code to print a Single Sheet<\/h1>\n
\r\nFunction PrintOneSheet()\r\n Sheets("Sheet1").PrintOut 'Sheet1 is the name of the Sheet which you want to Print\r\nEnd Function\r\n\r\n<\/code><\/pre>\n
5. VBA code to print more than one Sheet<\/h1>\n
\r\nFunction PrintMultipleSheets()\r\n Sheets(Array("Sheet1" , "Sheet2", "Sheet3").PrintOut \r\nEnd Function\r\n\r\n<\/code><\/pre>\n
6. VBA code to print Selected area of a Sheet<\/h1>\n
\r\nFunction PrintSelectedArea()\r\n Selection.PrintOut \r\nEnd Function\r\n\r\n<\/code><\/pre>\n
7. VBA code to print Range of Worksheet<\/h1>\n
\r\nFunction PrintRange()\r\n Range("A1:D5").PrintOut \r\nEnd Function\r\n\r\n<\/code><\/pre>\n
8. VBA code to print Excel Chart<\/h1>\n
\r\nFunction PrintChart()\r\n Sheets("Sheet1").ChartObjects("Chart1").Chart.PrintOut 'Chart1 is name of the Chart\r\nEnd Function\r\n\r\n<\/code><\/pre>\n
9. VBA code to print All Charts in a WorkSheet<\/h1>\n
\r\nFunction PrintAllChart()\r\nDim ExcelCharts As Object\r\nSet ExcelCharts = Sheets("Sheet1").ChartObjects\r\nFor Each Chart In ExcelCharts\r\n Chart.Chart.PrintOut\r\nNext\r\nEnd Function\r\n\r\n\r\n<\/code><\/pre>\n
10. VBA code to print All Charts in a Workbook<\/h1>\n
\r\nFunction PrintAllChart()\r\n\tDim ExcelCharts As Object\r\n\tFor Each Sheet In Sheets\r\n\t\tSet ExcelCharts = Sheet.ChartObjects\r\n\t\tFor Each Chart In ExcelCharts\r\n\t\t\tChart.Chart.PrintOut\r\n\t\tNext\r\n\t\tSet ExcelCharts = Nothing\r\n\tNext\r\nEnd Function\r\n<\/code><\/pre>\n
Example 2: VBA Statements to Print Objects with different parameters passed<\/h1>\n
1. VBA code to print From Page Number X<\/i> to Page Number Y<\/i><\/h2>\n
\r\n'Below statement will print from Page No:2 to Page No:3\r\nWorksheets("Sheet1").PrintOut From:=2, To:=3\r\n<\/code><\/pre>\n
2. VBA code to print more than 1 Copy<\/h2>\n
\r\n'Below statement will print 3 copy of the Sheet1 from Page 2 to Page no: 3\r\nWorksheets("Sheet1").PrintOut From:=2, To:=3, Copies:=3\r\n<\/code><\/pre>\n
3. VBA code to Show Print Preview before actual printing<\/h2>\n
\r\n'Below statement will print 3 copy of the Sheet1 from Page 2 to Page no: 3\r\nWorksheets("Sheet1").PrintOut From:=2, To:=3, Copies:=3, Preview:=True\r\n<\/code><\/pre>\n<\/span>","protected":false},"excerpt":{"rendered":"