[go: up one dir, main page]

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

PDF Code 2

The document contains a VBA macro that saves an active Excel sheet as a PDF file. It retrieves the invoice number and customer name from specific cells to construct the file name and checks if the specified file path exists. If the path is valid, it exports the sheet as a PDF and displays a confirmation message upon successful saving.

Uploaded by

Nebyou Tesfaye
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)
32 views1 page

PDF Code 2

The document contains a VBA macro that saves an active Excel sheet as a PDF file. It retrieves the invoice number and customer name from specific cells to construct the file name and checks if the specified file path exists. If the path is valid, it exports the sheet as a PDF and displays a confirmation message upon successful saving.

Uploaded by

Nebyou Tesfaye
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 SaveAsPDF()

Dim invoiceNo As String


Dim customerName As String
Dim fname As String
Dim Path As String

' Get invoice number and customer name from specific cells

invoiceNo = Range("F6").Value
customerName = Range("B10").Value

' Construct file name


fname = invoiceNo & " - " & customerName

' Specify file path


Path = "C:\Users\TAHA\Documents\YT\Short\"

' Check if the specified path exists


If Dir(Path, vbDirectory) = "" Then
MsgBox "The specified path does not exist.", vbExclamation
Exit Sub
End If

' Export active sheet as PDF


ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
ignoreprintareas:=False, _
fileName:=Path & fname

' Display confirmation message


MsgBox "PDF file saved successfully.", vbInformation

End Sub

You might also like