Search TeachExcel.com
TeachExcel.com
TE
Teach Excel MS Office Tutorials Excel Consulting Services Excel Forum
Excel Video Tutorials Excel Tips Free Excel Macros Excel Help Resources Contact TeachExcel
Video Tutorials
  • Free Macros
  • Excel Help Directory
  • Excel 2007 Resources
  • Keyboard Shortcuts
  • Excel Forum
  • Contact/About

Macros
Excel Tutorials For Macros

Print Specific Pages in Excel


Bookmark and Share

This free Excel macro allows you to print a pre-specified selection of pages from Excel. This means you can print 2 pages from a 10 page workbook or file or 4 pages from that workbook etc.

The macro allows you to choose which pages you want to print by inputting the number for the from and to argument. The from argument is the page number from which printing will start and the to number is the page number up to which will be printed.

You can also make this macro more dynamic in nature by setting the from and to arguments equal to variables and then get numbers for those variables from a user input box or dynamic worksheet calculation.
Where to install the macro:  Module

Macro to Print Specific Pages in Excel

Sub Print_Specific_Pages()
'Prints page x to page x
'You tell Excel which pages you want to print - i.e. pages 1 to 5; pages 4 to 7; etc.
'Replace the 5 with the page number from which you would like to start printing
'Replace the 10 with the page number to which you would like to print in Excel

Worksheets.PrintOut from:=5, to:=10

End Sub


Bookmark and Share


How to Install the Macro
  1. Select and copy the text from within the grey box above.

  2. Open the Microsoft Excel file in which you would like the Macro to function.

  3. Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.  Or For other ways to get there, Click Here.

      For Excel Versions Prior to Excel 2007
      Go to Tools > Macros > Visual Basic Editor

      For Excel 2007
      Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic

  4. On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.

  5. If the Macro goes in a Module, Click Here, otherwise continue to Step 8.

    1. Go to the menu at the top of the window and click Insert > Module
    2. Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
    3. Go to Step 8.

  6. If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Go to Step 8.

  7. If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
    5. Go to Step 8.

  8. Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.

  9. You are now ready to run the macro.



Similar Helpful Excel Resources

Print Specific Pages From Pdf Files With Excel - Excel

View Content
Hello,

I'd like to use Excel to print specific pages of a given list of PDF files.
I have a table with 2 columns (pdf_path | page_to_print)

Up to now, I can only manage 2 things (cf. code below):

1) Print the whole pdf
2) Open the pdf with Acrobat at a given page
I'd like to do both!
Thanks a lot for your answer & Have a nice day!

Code for 1)


Code:

Sub Open_PDF()
Dim NomFichier
   NomFichier = "F:\[...].pdf"
   If Dir(NomFichier)  "" Then
     ShellExecute 0, "print", NomFichier, "", "", 0
   Else
     MsgBox "Chemin ou fichier introuvable."
   End If
End Sub






Code for 2)


Code:

Public Sub Open_PDF_At_Page()

    Dim sPDFfile As String
    Dim sAdobeCommand As String
    Const cAdobeReaderExe As String = "C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe"
    
    sPDFfile = "F:\[...].pdf"
    
    sAdobeCommand = " /a ""page=10=Open Actions"" "
    
    Shell cAdobeReaderExe & sAdobeCommand & Chr(34) & sPDFfile & Chr(34), vbNormal

End Sub




Print Specific Pages Based On Specific Cells - Excel

View Content
I am trying to find a way to look at a specific worksheet and specific cells within that worksheet and if there is data displayed in that cell (there is a formula in the cell) print that page.

I searched the forum to see if I could write some VBA to do this but it seems most of the code that I found looks for the last cell with data and then sets the print area based upon that.

To be clear....I have a worksheet that has printable pages (A1:H35 is one page, A36:H70 the next, then I1:P35 and so on). The top few rows have hard data that is the same on all. I want to look at a certain cell (E9,M9,E44, etc.) and print that page if there is data (again there is a formula in that cell). I am guessing this is somewhat easy with VBA?? Any help is greatly appreciated.

Print Specific Pages - Excel

View Content
In a worksheet I enter data in some cells and then I print the whole worksheet. Each page is identified by a string, say PG1, PG2, PG3 etc. which is located in a specific cell of the page. I need the code to search the worksheet for a string I input and when it match it with the ID string (PG1, PG2, PG3 ...) to print ONLY the corresponding page.
Thanks

Can You Print A Specific Number Of Pages? - Excel

View Content
I have an excel spreadsheet and want to be able to set the number of pages to be printed using an inputbox or something in excel vb? Does anyone know if this is possible?

Thanks

Alex

Print Specific Number Of Pages? - Excel

View Content
I have an excel spreadsheet and want to be able to set the number of pages to be printed using an inputbox or something in excel vb? Does anyone know if this is possible?

Thanks

Alex

Use Different Print Orientation Specific To Different Pages On Worksheet - Excel

View Content
I have 2 pages on a single sheet and I want to print my 1st page Horizontally and my 2nd page Vertically when I click the "Print" button. How can I do so? Currently the page setup that I managed to set is to print either Horizontally or Vertically for both pages .

Can anyone help me? Thank you.

Print Area And Fitting Rows Onto Specific Pages - Excel

View Content
I have a defined print area, A1:L134

I want it to print 3 pages, no more, no less.

I have the page setup, page tab set to fit to 1 page wide by 3 pages tall.

I have tried page breaks but the seem to do nothing.

I want rows 1-60 on page 1, 61-110 on page 2, and rows 111 - 134 on page 3.

How can this be acheived?

How To Print Odd Pages And Even Pages Seperately In Excel. - Excel

View Content
How to print odd pages and even pages seperately. For ex I have 100 pages
with page numbers customized to read "001" upto "100" and I want to print all
"Even pages" first then at the reverse side I want to print all "odd pages".

How to complete this task in two setp printing.


Print Specific Pages In Worksheet Based On Cell Data - Excel

View Content
Hello,

I have a worksheet with 20 pages in it. Each page is actually a report. I need a macro which will test to see which reports have been done, and then print only those pages.

For example, there has been a report entered in page 1, 2 and 4, but not 3. So I want the macro to print pages 1,2 and 4, but not 3.

For the purposes of the macro, I can have a range of cells, say for argument's sake, A1:A20, with either 1 or 0 in them depending on whether the page is to be printed or not. If page 1 is to be printed, A1 will have the value 1 in it; A2 will have 1 if page 2 is to be printed; A3 will have 0 in it and therefore page 3 will not be printed, and finally A4 will have 1 in it and page 4 will be printed.

I thought I would easily be able to find something about this online, but I've only found references to printing entire worksheets, not specific pages within a worksheet.

Thank you very kindly to anyone who is able to help me with this.

Nicholas Stone

Excel Won't Print All Pages - Excel

View Content
I've never encountered this before. Let me preface that I am a 20+ year user of Excel. Currently using Excel 2007.

I have 43 pages set up to print which encompasses 75 rows and 271 columns (I am using Page Break Preview when viewing the spreadsheet). Whenever I attempt to print, or review with Print Preview, only 37 pages are generated (through column #244).

There is no print area defined (only print titles). Any ideas? Thanks.

Random Tutorials
Goal Seek Feature in Excel
(Intermediate)
Remove #N/A Error Result from Empty VLOOKUP() Formulas
(Intermediate)
Introduction to Making Formulas in Excel
(Easy)
Function and Formulas Lookup in Excel
(Easy)
Link Cells Between Worksheets
(Easy)
Consolidate & Combine Data from Separate Worksheets or Workbooks(Excel Files)
(Intermediate)
Submit Inquiry Here
  • Prices From $10
Name:*
E-mail:*
Request:*
The macro(s) on this page will be sent with the request.
Contact | Privacy Policy | Disclaimer
Copyright© 2012 TeachExcel.com