Selecting and printing a range and a worksheet

hemis

New Member
Joined
Jun 11, 2016
Messages
13
hello

I am trying to combine a single page of a worksheet with another worksheet and print to a file. I want page 1 to print on its own (its a summary of the other sheets), page 2 to front sheet1, page 3 to front sheet2 etc.

I have managed to select each page and each worksheet, but when I try to printout I get an error.

This is my code:
For sheetIndex = 1 To numberOfSheets - 1 Step 1
sheetName = Sheets(sheetIndex).Name
If (sheetIndex = 1) Then
sheetName = "Summary"
topSheetFileName = projectReference & projectRevision & " - " & sheetName & ".pdf"
Sheets("TS1").PrintOut from:=sheetIndex, To:=sheetIndex, printtofile:=True, prtofilename:=topSheetFileName
End If

If (sheetIndex > 1) Then
Sheets("TS1").Activate
Set topSheet = Sheets("TS1").Range(Cells((sheetIndex - 1) * n + 1, 1), Cells(sheetIndex * n, 9))
topSheet.Select
'Stop
Set calcSheet = Sheets(sheetIndex)
calcSheet.Activate
'This all works and selects

'Now if I try to print the two ranges I get an error

Sheets(Array(topSheet, calcSheet)).PrintOut
'Stop
End If
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,215,467
Messages
6,124,984
Members
449,201
Latest member
Lunzwe73

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