How to print worksheets from a different work book?

Ivn68

Board Regular
Joined
Aug 21, 2015
Messages
82
Private sub command button1_click()
If Range("J15").value=4 then
Workbooks("c:\ tournament\bad beat\ receipt file.xlsm").worksheets(array("1","2","3","4")).printout
Else
End if
End sub

Says script out of range
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try this.
First open the workbook.


Check the name of the book and its sheets.

Code:
[COLOR=#333333]If Range("J15").value=4 then[/COLOR]
[COLOR=#333333]   Workbooks("receipt file.xlsm").Sheets(array("1","2","3","4")).printout[/COLOR]

[COLOR=#333333]End if[/COLOR]
 
Upvote 0
Is that number 4 from cell J15 the first four sheets to be printed? Or the actual sheet names.
If it is the first four sheets, this should work.

Code:
Sub Maybe()
Dim wb1 As Workbook, wb2 As Workbook, i As Long
Application.ScreenUpdating = False
Set wb1 = ThisWorkbook
Set wb2 = Workbooks.Open("c:\ tournament\bad beat\ receipt file.xlsm")
    For i = 1 To wb1.Sheets("Sheet1").Range("J15").Value    '<---- Change sheet name to actual name
        wb2.Sheets(i).PrintOut
    Next i
wb2.Close False
Application.ScreenUpdating = True
End Sub

If the numbers are actual sheet names (that is what it looks like) you'll have to change it to what DanteAmor showed you
 
Upvote 0
I named the sheets "1" "2" "3" "4"
I don't have to put in the whole file name where it's located? Like the "c:" drive part?
 
Upvote 0
Sooo what I'm trying to do is I have a main sheet where I enter all this data. Afterwards I have a button on the sheet and it prints all the receipts I need. I want the receipts to be in a separate worrkbook
So when I save the main work sheet it doesn't have to save the copies of the receipts. I don't want to waste space
Does that make any sense?
 
Upvote 0
Could you explain step by step what you want to do?
Include ranges, sheets, where to store usw usw.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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