Print only selected sheets

punit

New Member
Joined
Mar 11, 2012
Messages
3
Hello Everyone !

I have just started to use VB in excel.
I have 5 sheets containing data but now from these 5 sheets i don't want that anyone can print sheet2 because its my main sheet ( This sheet contains Pivot table in it).

I have searched and tried many code from internet but didn't work any one of them for me.

So please if any one can freshly guide me step by step, i will be greatful.

Other than that also i want to know if i can hide only the tabs in excel and not sheets

Thanx in Advanced
Punit.
 
Try like this

Code:
Sub prt()
Sheets(Array("Sheet1", "Sheet3", "Sheet4", "Sheet5")).PrintOut
End Sub

You can hide ALL the tabs like this

Code:
ActiveWindow.DisplayWorkbookTabs = False
 
Upvote 0
Variable "sheetToSkip" keeps sheet name which you do want to be printed. Adjust to your needs. This code skips chart sheets if they exist in your workbook.
Code:
Sub PrintSheets()

    Dim sheetToSkip As String, i As Integer
    Dim sheet As Object, arr() As Variant
    
    sheetToSkip = "Sheet1"
    
    For Each sheet In Sheets
        If TypeOf sheet Is Worksheet Then
            i = i + 1
            ReDim Preserve arr(1 To i)
            arr(i) = sheet.Name
        End If
    Next

    Sheets(arr).PrintOut

End Sub
 
Upvote 0
Hello,

First of all thanx ( to VoG )for quick reply.

This didn't work for me

Sub prt() Sheets(Array("Sheet1", "Sheet3", "Sheet4", "Sheet5")).PrintOut End Sub
 
Last edited:
Upvote 0
You need to use the actual names of the sheets.


Hello

Maybe i am making some mistake.
Is it possible if you can apply code and export it and than i will import in vbcode editor ?

Because i am very new with all this things.

Thanx
 
Upvote 0
Press ALT + F11 to open the Visual Basic Editor. Select Module from the Insert Menu. Paste in

Code:
Sub prt()
Sheets(Array("Sheet1", "Sheet3", "Sheet4", "Sheet5")).PrintOut
End Sub
Change Sheet1 and so on to the actual names of your sheets. Press ALT + Q to close the code window.

Press ALT + F8 then double click prt
 
Upvote 0

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