Required A VBA

alihamza2247

New Member
Joined
Aug 25, 2018
Messages
5
I need some help about excel vba.
I want to print some specific excel hidden sheets with selected cells range via VBA.for example i"m working in sheet1, and sheet2,sheet3 and sheet4 are hidden so I want to make some buttons in sheet1 for printing those sheets with cell range (A1:N30).so please provide me an VBA for doing this.

Thanks
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Welcome to Mr. Excel !

Try the below VBA code assuming the workbook is not password protected

Code:
Sub Print_Sheets()
Dim ws As Worksheet, Chk As Boolean
Application.ScreenUpdating = False
For Each ws In Worksheets(Array("Sheet1", "Sheet2", "Sheet3")) ' <-- just include the sheets you wnat to print here
    If ws.Visible = False Then
        ws.Visible = xlSheetVisible
        Chk = True
    End If
    ws.Range("A1:N30").PrintOut
    If Chk = True Then
        ws.Visible = xlSheetHidden
        Chk = False
    End If
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Re: Required A VBA for Printing a Hidden Excel Sheet

Sub Print_Sheets()
Dim CurStat As Variant
For Each ws In Worksheets(Array("Daily Sales")) ' <-- just Replace All ("Daily Sales") with your sheet name which you waat to print'
If Not Sheets("Daily Sales").Visible Then
CurStat = Sheets("Daily Sales").Visible
Sheets("Daily Sales").Visible = xlSheetVisible
Range("A1:N30").Select
Sheets("Daily Sales").PageSetup.printarea = "A1:N30"
Sheets("Daily Sales").PrintOut From:=1, To:=1, Copies:=1, Collate _
:=True
Sheets("Daily Sales").Visible = CurStat
End If
Next
End Sub
 
Upvote 0
[h=2]Required A VBA for Printing a Hidden Excel Sheet[/h]thanks bro for your kind response
i used above VBA and works perfectly
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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