Printing an Array of xlsx worksheets from a separate xlsm file

Stevep4

New Member
Joined
Aug 28, 2015
Messages
35
I'm trying to figure out code that will print out specific worksheets from an xlsx file from an xlsm file. Let's say the file I want to print sheets off of is Print.xlsx and I want to print tabs Sheet1 and Sheet2. I created an xlsm file and have this code:

Code:
Sub PrintPages()
 Dim wb As Workbook
    Set wb = Workbooks.Open("S:\Business Analysis\Print.xlsx"")
    Application.Dialogs(xlDialogPrinterSetup).Show
    wb.Worksheets(Array("Sheet1", "Sheet2")).PrintOut
End Sub
This code actually works. Only, it opens the file I want to print from. For several reasons, I just want the code to establish Print.xlsx and print the desired tabs, not open the workbook, as it's already open. So, the set wb above is really causing me problems. If I take out the Open, it doesn't work. I'm not sure how to simply establish Print.xlsx without opening it.

Thanks
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
The following macro first checks whether Print.xlsx is opened. If so, it proceeds to print your array of worksheets.

Code:
Sub PrintPages()

    Dim wb As Workbook
    
    On Error Resume Next
    Set wb = Workbooks("Print.xlsx")
    If wb Is Nothing Then
        MsgBox "Workbook is not open!", vbExclamation
        Exit Sub
    End If
    On Error GoTo 0
    
    Application.Dialogs(xlDialogPrinterSetup).Show
    
    wb.Worksheets(Array("Sheet1", "Sheet2")).PrintOut
    
End Sub

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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