VBA to exclude One Sheet from printing

smhutch

New Member
Joined
Aug 13, 2009
Messages
18
I have a code to print all visible sheets that already works successfully. However, I have a main input sheet that I don't want to ever print.

Any ideas on a script for my special Print button to print all visible sheets but exclude my main sheet from printing?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
post your code if you want specifics, but something like this would print everything except sheet1

Code:
Sub PrintSheets()
 Dim ws As Object
    For Each ws In Application.Worksheets
    If ws.Name <> "Sheet1" Then _
    ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)"
    Next
End Sub
 
Upvote 0
post your code if you want specifics, but something like this would print everything except sheet1

Code:
Sub PrintSheets()
 Dim ws As Object
    For Each ws In Application.Worksheets
    If ws.Name <> "Sheet1" Then _
    ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)"
    Next
End Sub
Private Sub CommandButton1_Click()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Visible = xlSheetVisible Then
ws.PrintOut
Exit Sub
End If
Next ws
End Sub

That is what I want it to do, but I don't want my Sheets("Main") to print.
 
Upvote 0
Try this:

Code:
Private Sub CommandButton1_Click()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Visible = xlSheetVisible and ws.name <> "Main" Then
ws.PrintOut
Exit Sub
End If
Next ws
End Sub
I don't understand why you are exiting the code after it does the print out though? Is it actually printing all the sheets?

Hope that helps.
 
Upvote 0
Code:
Private Sub CommandButton1_Click()
 Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
        If ws.Visible = xlSheetVisible And _
         ws.Name <> "Main" Then ws.PrintOut
    Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top