Excel Macro Print to PDF

mazher

Active Member
Joined
Nov 26, 2003
Messages
363
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi ALL,

I am using this macro to print the invoices in the separate PDF file.

Please can someone modify to code to print the all invoices in one PDF file.

Sub PrinttoPdf1()
Dim i As Integer
Dim Startrange As Integer
Dim Endrange As Integer
Dim PSh As Worksheet
Dim PPath As String

On Error GoTo errHandler


Set PSh = Sheets("Inv BCC")
Startrange = PSh.Range("M2").Value
Endrange = PSh.Range("N2").Value
PPath = PSh.Range("o2").Value

For i = Startrange To Endrange

PSh.Range("h14").Value = PSh.Range("n12").Offset(i, 0).Value
Printfile = PSh.Range("h14").Value

PSh.Range("A1:I37").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=PPath & Printfile & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False


Next i

exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file" & vbNewLine & vbNewLine & "Please check the input parameters & print location" & vbNewLine & "Please double check if the file location exists and is in correct format" & vbNewLine & vbNewLine & "C:\PDF Export\May2018"
Resume exitHandler
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Re: Excel Macro Print to PDF -VBA Gurus Help

Try this Code

Sub TurnTabIntoPDF1()
'
' TurnTabIntoPDF Macro
'
Range("A1:T22").Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$T$22"
With ActiveSheet.PageSetup
.Orientation = xlLandscape
.PaperSize = xlPaperA5
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ActiveWorkbook.Path & "" & .Range("Q5") & " " & .Range("O5").Value & " " & .Range("E6").Value & " " & .Range("P6").Value, Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End With
End Sub
 
Upvote 0
Re: Excel Macro Print to PDF -VBA Gurus Help

Try this Code

Sub TurnTabIntoPDF1()
'
' TurnTabIntoPDF Macro
'
Range("A1:T22").Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$T$22"
With ActiveSheet.PageSetup
.Orientation = xlLandscape
.PaperSize = xlPaperA5
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ActiveWorkbook.Path & "" & .Range("Q5") & " " & .Range("O5").Value & " " & .Range("E6").Value & " " & .Range("P6").Value, Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End With
End Sub

Try this the fist on is with data in cell's
 
Upvote 0
Re: Excel Macro Print to PDF -VBA Gurus Help

Try this the fist on is with data in cell's

Thanks Hjemmet,

I don't know what the macro is doing but its not working.

The code I have posted is making the separate pdf files, I just want to combine all the pdf files.

Hopefully some can give me a solution.

Thanks
 
Upvote 0
Re: Excel Macro Print to PDF -VBA Gurus Help

Sorry havent read that part where you Combine Pdf files
 
Upvote 0
Re: Excel Macro Print to PDF -VBA Gurus Help

Please can someone help me that.

Thanks
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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