Excel VBA: Create Invoice and Save PDF Format (with Quick Steps)

Create an Invoice and Save it in the PDF Format with Excel VBA (Quick View)

Private Sub Create_invoice_save_pdf()
'for invoice number
Sheet2.Range("C5").Value = Sheet2.Range("C5").Value + 1
'for pdf file save
Sheet1.Range("B2:E20").ExportAsFixedFormat xlTypePDF, Filename:=_"C:\Invoice\" & Sheet.Range("C5").Value, openafterpublish:=True
'for clear invoice
Sheet2.Range("B12:E15").ClearContents
Sheet2.Range("E17:E19").ClearContents
End Sub

Save PDF Format with Excel VBA


How to Create an Invoice and Save it in the PDF Format with Excel VBA: 2 Easy Steps

We have a dataset that contains information about the invoice of the Star Restaurant. We will save it into a PDF format.

Use SUM Function to Create Invoice and Save PDF Format


Step 1 – Use the SUM Function to Create an Invoice

  • Select cell E12.

 

  • Insert the following formula:
=C12*D12

Use SUM Function to Create Invoice and Save PDF Format

  • Hit Enter.

  • AutoFill the SUM function to the rest of the cells in column E.

Use SUM Function to Create Invoice and Save PDF Format

  • Select cell E17 and use the following SUM function in that cell:
=SUM(E12:15)

  • Hit Enter.

Use SUM Function to Create Invoice and Save PDF Format

  • We will give a 5% discount to the customer. Select cell E19 and insert the following formula:
=E17*95%

Use SUM Function to Create Invoice and Save PDF Format

  • Hit Enter.

create invoice and save pdf format excel vba

Read More: Excel Macro to Save as PDF with Filename from Cell Value


Step 2 – Save the File as a PDF

  • Go to Developer and select Visual Basic.

Save PDF Format with Excel VBA

  • A window named Microsoft Visual Basic for Applications – Invoice will appear.
  • Select Insert and choose Module.

  • In the module, insert this VBA code:
Private Sub Create_invoice_save_pdf()
'for invoice number
Sheet2.Range("C5").Value = Sheet2.Range("C5").Value + 1
'for pdf file save
Sheet1.Range("B2:E20").ExportAsFixedFormat xlTypePDF, Filename:=_"C:\Invoice\" & Sheet.Range("C5").Value, openafterpublish:=True
'for clear invoice
Sheet2.Range("B12:E15").ClearContents
Sheet2.Range("E17:E19").ClearContents
End Sub

Save PDF Format with Excel VBA

  • Go to Run and press Run Sub/UserForm or hit F5.

  • Here’s the resulting file.

Save PDF Format with Excel VBA

Read More: Excel Macro: Save as PDF with Date in Filename


Things to Remember

If the Developer tab is not visible in your ribbon, you need to make it visible. To do that, go to File → Option → Customize Ribbon


Download the Practice Workbook


Related Articles

Get FREE Advanced Excel Exercises with Solutions!
Md. Abdur Rahim Rasel
Md. Abdur Rahim Rasel

MD. ABDUR RAHIM is a marine engineer proficient in Excel and passionate about programming with VBA. He views programming as an efficient means to save time while managing data, handling files, and engaging with the internet. His interests extend to Rhino3D, Maxsurf C++, AutoCAD, Deep Neural Networks, and Machine Learning, reflecting his versatile skill set. He earned a B.Sc in Naval Architecture & Marine Engineering from BUET, and now he has become a content developer, creating technical content... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo