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 Selected Worksheets in Excel


Bookmark and Share

This free excel macro will print all selected worksheets in Excel. If there are no other worksheets selected the active worksheet will be printed.

This is a great little macro to include in a workbook and attach to a button in Excel. This will allow you to prevent menu commands from being run, such as for a data entry or job application form but still allow the user to print the worksheet he/she is using.
Where to install the macro:  Module

Print The Selected Worksheets or Current Worksheet in Excel

Sub Print_Current_Sheet()
'Prints the current or selected worksheets in Excel

ActiveWindow.SelectedSheets.PrintOut

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

How Not To Print Selected Worksheets - Excel

View Content
I have lot of worksheets. It takes lot of time to print each of them individually. I also have some worksheets which I don't need to print.

Is there any way to print only the required worksheets when I print the whole workbook. Please suggest. Thank you.

Print Selected Worksheets In Workbook - Excel

View Content
I have a workbook with multiple sheets. I need a step by step process on adding a control button with code that will allow me to print only selected worksheets. For instance I may want to print sheets 1, 2 & 5 and another time could be sheets 1, 3 & 5. So the control button should probably have check boxes beside the sheet names to allow printing.

Vba Code To Print Selected Worksheets - Excel

View Content
I used the code from here and encountered some issues. The first problem is the last worksheet becomes the active worksheet regardless of which sheet the user was on. In addition, the last worksheet is always printed, even if it was not selected. It appears there is a fix for this in this post that I did add to but figured I should start a new post so I apologize for the duplicate. However, I am unable to incorporate it so that it works completely. I have also added a 'Printer Setup' and a 'Number of Copies' dialog boxes (they probably need to be placed elsewhere in the code). The two additions I would like to make is to have the ability to select all 'Checkboxes' at one time and to have all of the pages print sequentially. I have included my best attempt (some sections may be duplicated/commented out as I tried to correct), but I am in no way a programmer. Any help is appreciated. Thank you.

Private Sub CommandButton1_Click()

'Display "Printer Setup" dialog box
Application.Dialogs(xlDialogPrinterSetup).Show

'Option Explicit

'Sub SelectSheets()
Dim i As Integer
Dim TopPos As Integer
Dim SheetCount As Integer
Dim PrintDlg As DialogSheet
Dim CurrentSheet As Worksheet
Dim cb As CheckBox
Application.ScreenUpdating = False

' Check for protected workbook
If ActiveWorkbook.ProtectStructure Then
MsgBox "Workbook is protected.", vbCritical
Exit Sub
End If

' Add a temporary dialog sheet
Set CurrentSheet = ActiveSheet
Set PrintDlg = ActiveWorkbook.DialogSheets.Add

SheetCount = 0

' Add the checkboxes
TopPos = 40
For i = 1 To ActiveWorkbook.Worksheets.Count
Set CurrentSheet = ActiveWorkbook.Worksheets(i)
' Skip empty sheets and hidden sheets
If Application.CountA(CurrentSheet.Cells) 0 And _
CurrentSheet.Visible Then
SheetCount = SheetCount + 1
PrintDlg.CheckBoxes.Add 78, TopPos, 150, 16.5
PrintDlg.CheckBoxes(SheetCount).Text = _
CurrentSheet.Name
TopPos = TopPos + 13
End If
Next i

' Move the OK and Cancel buttons
PrintDlg.Buttons.Left = 240

' Set dialog height, width, and caption
With PrintDlg.DialogFrame
.Height = Application.Max _
(68, PrintDlg.DialogFrame.Top + TopPos - 34)
.Width = 230
.Caption = "Select sheets to print"
End With

' Change tab order of OK and Cancel buttons
' so the 1st option button will have the focus
PrintDlg.Buttons("Button 2").BringToFront
PrintDlg.Buttons("Button 3").BringToFront

' Display the dialog box
CurrentSheet.Activate
Application.ScreenUpdating = True
If SheetCount 0 Then
If PrintDlg.Show Then
For Each cb In PrintDlg.CheckBoxes
If cb.Value = xlOn Then
Worksheets(cb.Caption).Activate
ActiveSheet.PrintOut
' ActiveSheet.PrintPreview 'for debugging
End If
Next cb
End If
Else
MsgBox "All worksheets are empty."
End If

' Delete temporary dialog sheet (without a warning)
Application.DisplayAlerts = False
PrintDlg.Delete

' Reactivate original sheet
CurrentSheet.Activate

End Sub

Macro To Print All Or Selected Worksheets - Excel

View Content
I have a workbook that has about 20-25 worksheets, is it possible to create a macro that will allow you to either print the entire workbook or to select the tabs you want to print.

Print Multiple Selected Worksheets To Separate Pdf's - Excel

View Content
Hi,

I have the following code which I am using to print to PDF

Code:

ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"CutePDF Writer", Collate:=True
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 2
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
Filename = "I:\2010-2011 Year\REGISTER 2010-2011\Invoices\PDF invoices\" & ActiveSheet.Range("F13").Value
SendKeys Filename & "{ENTER}", False


It's working for what I need but it could be just a little bit better. Currently I have to use the macro to print each worksheet separately to get a separate PDF document. Is it possible to adapt this slightly? Basically it would be great if the macro would print each worksheet in the workbook containing text "Invoice" in the worksheet name to a separate PDF, the filename and path to remain as is in the code above. I also like the 2 second delay.

Workbook is called Header & Footer (if this is required).

Many thanks for any assistance which can be provided.

Print Selected Sheets In Excel - Excel

View Content
I have to create a userform with several checkboxes to select particular
sheets for printing. Check one box will select one sheet. A "Print"
button is created with the code:

Private Sub CommandButton1_Click()

ActiveWorkbook.SelectedSheets.PrintOut Copies:=1
Unload Me

End Sub

Please advice how to pass the checked sheets for printing. Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Excel - Cannot Print Borders In Color(s) I Have Selected - Excel

View Content
I would like to print Excel Worksheet Borders in COLOR. [ I already know how
to select/change the border color! ] Once I have done so, the border is
displayed in the appropriate color on my monitor - for example, RED.
However, when I PRINT the worksheet, the borders print BLACK. (All other
items, text, objects, WordArt, etc. print properly.) I have tried this on
several PC's and printers - inkjet and laser - at the office and at home -
each with the same result.

NOTE: I have tried this with Office 2000 and Office XP ...


Excel 2003 Print Problem With Conditional Formatting Cell Selected - Excel

View Content
Whenever I try to print or ask for a print preview of my worksheet while a cell with conditional formatting is selected, Excel 2003 crashes. Printing the exact same worksheet while another cell is selected works fine... any ideas?

Gridlines Will Not Print If Print Titles Is Selected - Excel

View Content
Why won't the gridlines print if I have selected the first two rows on a page to print as titles? The autofill is OFF.

How To Duplex Print Excel Worksheets - Excel

View Content
I'm trying to print selected work sheets in a workbook back to back using a
duplex printer. I'm having no luck. With the printer properties set to
duplex each selected worksheet prints on a separate page.


Random Tutorials
Introduction to Making Formulas in Excel
(Easy)
HLOOKUP() Function - Introduction
(Intermediate)
Consolidate & Combine Data from Separate Worksheets or Workbooks(Excel Files)
(Intermediate)
Assign Keyboard Shortcuts to Macros
(Easy)
Formatting Worksheets for Printing in Excel
(Easy)
How to 'Protect' a Worksheet and Workbook
(Easy)
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