Multiple printing to PDF

jrisebo

Active Member
Joined
Mar 15, 2011
Messages
312
Office Version
  1. 365
Platform
  1. Windows
Im using the following code to print a sheet that changes a value each time. Its working fine. Only issue is that I have to save each print as a seperate PDF. How do I get them to be all in one file?

VBA Code:
Private Sub CommandButton1_Click()



For x = 1 To 100 'increase the 100 to a larger number if you ever have more than 100 sheets

If Sheets("Sheet2").Range("T" & x).Value = "" Then Exit Sub

Sheets("Sheet2").Range("F4").Value = Sheets("Sheet2").Range("T" & x).Value

Sheets("Sheet2").Range("F3").Value = Sheets("Sheet2").Range("U" & x).Value

ActiveSheet.PrintOut Copies:=1, Collate:=True

Next

End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I did find a way in my printer preferences to 'append' each time it prints to the original PDF, but I have to hit save for each time. I have 50 so incidents so I have to hit save 50 times. Annoying, but workable. Still would like to automate via the code.
 
Upvote 0
I got this to do what I wanted, or close enough.
VBA Code:
Private Sub CommandButton1_Click()

For x = 1 To 100 'increase the 100 to a larger number if you ever have more than 100 sheets

If Sheets("Sheet2").Range("T" & x).Value = "" Then Exit Sub

Sheets("Sheet2").Range("F4").Value = Sheets("Sheet2").Range("T" & x).Value

Sheets("Sheet2").Range("F3").Value = Sheets("Sheet2").Range("U" & x).Value

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\test" & x & ".pdf"

Next

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,327
Messages
6,124,294
Members
449,149
Latest member
mwdbActuary

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