I got this code from Chat GPT.
I asked it if it could give me code to print a PDF with page breaks.
But I don’t think this will do what I want it to.
For context, I’ve inherited a file which prints data in certain tabs as PDFS, but a user is also to select multiple tabs, so that one PDF with multiple pages (the different tabs) is printed.
One of the tabs has a document that sometimes caries in length. It’s usually one page, but is occasionally 5 pages, depending on the task.
What’s the best way to alter the data that is printed from that page, when it is 5 pages long? I assume I’d need to put in page breaks where I want the text to ‘break’ before it spills over to the next page?
Here’s the sample code from Chat GPT:
I asked it if it could give me code to print a PDF with page breaks.
But I don’t think this will do what I want it to.
For context, I’ve inherited a file which prints data in certain tabs as PDFS, but a user is also to select multiple tabs, so that one PDF with multiple pages (the different tabs) is printed.
One of the tabs has a document that sometimes caries in length. It’s usually one page, but is occasionally 5 pages, depending on the task.
What’s the best way to alter the data that is printed from that page, when it is 5 pages long? I assume I’d need to put in page breaks where I want the text to ‘break’ before it spills over to the next page?
Here’s the sample code from Chat GPT:
VBA Code:
Sub PrintPDFWithPageBreaks()
' Define the path and filename of the PDF file to print
Dim filePath As String
filePath = "C:\path\to\your\pdf\file.pdf"
' Open the PDF file
Dim pdfApp As Object
Set pdfApp = CreateObject("AcroExch.App")
Dim pdfDoc As Object
Set pdfDoc = CreateObject("AcroExch.PDDoc")
pdfDoc.Open filePath
' Print the PDF file with page breaks
pdfDoc.PrintPagesSilent 0, pdfDoc.GetNumPages - 1, 1, True
' Close the PDF file and exit
pdfDoc.Close
Set pdfDoc = Nothing
Set pdfApp = Nothing
End Sub