0% found this document useful (0 votes)
2 views1 page

Code

The document is a VBA macro that automates the process of creating a combined PDF from an Excel worksheet. It duplicates the active sheet twice, sets specific headers for each version, and exports them as a single PDF file. After exporting, it deletes the duplicate sheets to clean up the workbook.

Uploaded by

Nilesh156
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Code

The document is a VBA macro that automates the process of creating a combined PDF from an Excel worksheet. It duplicates the active sheet twice, sets specific headers for each version, and exports them as a single PDF file. After exporting, it deletes the duplicate sheets to clean up the workbook.

Uploaded by

Nilesh156
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Sub PrintScreen()

Dim FilePath As String


Dim FileName As String
Dim FullPath As String
Dim wsOriginal As Worksheet
Dim wsDuplicate As Worksheet
Dim wsTriplicate As Worksheet

' Define the folder path to save the combined PDF (you can modify this path)
FilePath = "D:\PES\P.E.S\invoice\Oct.24\pdf oct24\" ' Modify as needed

' Set the file name for the combined PDF


FileName = "Invoice_Combined.pdf"

' Full path of the PDF


FullPath = FilePath & FileName

' Copy the active sheet for each print version


Set wsOriginal = ActiveSheet
wsOriginal.Copy After:=wsOriginal ' Create the Original copy first
Set wsDuplicate = ActiveSheet ' Create the Duplicate copy second
wsDuplicate.Copy After:=wsDuplicate ' Create the Triplicate copy last
Set wsTriplicate = ActiveSheet

' Set the headers for each version


wsOriginal.PageSetup.RightHeader = "ORIGINAL FOR RECIPIENT"
wsDuplicate.PageSetup.RightHeader = "DUPLICATE FOR TRANSPORTER"
wsTriplicate.PageSetup.RightHeader = "TRIPLICATE FOR SUPPLIER"

' Select the sheets in the correct order: Original, Duplicate, Triplicate
Worksheets(Array(wsOriginal.Name, wsDuplicate.Name, wsTriplicate.Name)).Select

' Export the sheets as a single PDF in the correct order


ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FullPath,
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False,
OpenAfterPublish:=False

' Delete the duplicate sheets after export


Application.DisplayAlerts = False
wsDuplicate.Delete
wsTriplicate.Delete
Application.DisplayAlerts = True
End Sub

You might also like