How to print worksheets from a different work book?

Ivn68

Board Regular
Joined
Aug 21, 2015
Messages
70
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

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
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,213,501
Messages
6,114,010
Members
448,543
Latest member
MartinLarkin

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