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

While working with large Microsoft Excel, sometimes we need to create an invoice and save the invoice into PDF format. We can easily do that by using the VBA Macros. Applying a VBA code to create an invoice and save it into PDF format is an easy task. Today, in this article, we’ll learn two quick and suitable steps to create an invoice and save PDF format by applying the VBA code in Excel effectively with appropriate illustrations.


Create Invoice and Save 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


Download Practice Workbook

Download this practice workbook to exercise while you are reading this article.


2 Easy Steps to Create Invoice and Save PDF Format with Excel VBA

Let’s say, we have a dataset that contains information about the invoice of the Star Restaurant. After that, we will save it into PDF format by using the VBA macros. We will apply the SUM function to create an invoice of the Star Restaurant. Here’s an overview of the dataset for today’s task.

Use SUM Function to Create Invoice and Save PDF Format


Step 1: Use SUM Function to Create Invoice and Save PDF Format

First of all, we will create an invoice of the Star restaurant. Let’s follow the instructions below to learn!

  • First, select cell E12.

 

  • After selecting cell E12, write down the below mathematical formula in that cell.
=C12*D12

Use SUM Function to Create Invoice and Save PDF Format

  • Simply ENTER on your keyboard, and you will get $750.00 as the return of the mathematical formula.

Use SUM Function to Create Invoice and Save PDF Format

  • After that, select cell E17 and type the below SUM function in that cell. The SUM function is,
=SUM(E12:15)

  • Further, again, press ENTER on your keyboard, and you will get $1670.00 as the return of the SUM function.

Use SUM Function to Create Invoice and Save PDF Format

  • Now, we will give 5% discount to the customer depending on the sell value. To calculate the discounted price, select cell E19, and type the below formula in that cell. The mathematical formula is,
=E17*95%

Use SUM Function to Create Invoice and Save PDF Format

  • Again, press ENTER on your keyboard, and you will get $1586.50 as the return of the mathematical formula which has been given in the below screenshot.

create invoice and save pdf format excel vba

Read More: Excel Macro to Save as PDF with Filename from Cell Value (2 Examples)


Similar Readings


Step 2: Save PDF Format with Excel VBA

Now we will apply the VBA code to save the PDF file of the invoice that has been created in step 1. This is an easy and time-saving task. Let’s follow the instructions below to save PDF format of the invoice!

  • First of all, open a Module, to do that, firstly, from your Developer tab, go to,

Developer → Visual Basic

Save PDF Format with Excel VBA

  • After clicking on the Visual Basic ribbon, a window named Microsoft Visual Basic for Applications – Invoice will instantly appear in front of you. From that window, we will insert a module for applying our VBA code. To do that, go to,

Insert → Module

  • Hence, the Invoice module pops up. In the Invoice module, write down the below VBA
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

  • Hence, run the VBA To do that, go to,

Run → Run Sub/UserForm

  • After running the VBA code, you will be able to save PDF format of the invoice of the Star Restaurant which has been given in the below screenshot.

Save PDF Format with Excel VBA

Read More: Print Range to PDF with VBA in Excel (5 Easiest Examples)


Things to Remember

👉 You can pop up Microsoft Visual Basic for Applications window by pressing Alt + F11 simultaneously.

👉 If a Developer tab is not visible in your ribbon, you can make it visible. To do that, go to,

File → Option → Customize Ribbon


Conclusion

I hope all of the suitable methods mentioned above to create an invoice and save the invoice into PDF format with VBA code will now provoke you to apply them in your Excel spreadsheets with more productivity. You are most welcome to feel free to comment if you have any questions or queries.


Related Articles

Md. Abdur Rahim Rasel

Md. Abdur Rahim Rasel

Hi! I'm Md. Abdur Rahim Rasel. Welcome to my Profile. Currently, I am working and doing research on Microsoft Excel and here I will be posting articles related to this. I have completed my graduation in Naval Architecture and Marine Engineering(NAME) from Bangladesh University of Engineering and Technology(BUET). I have a passion for learning new things with my knowledge through perseverance and hard work.

We will be happy to hear your thoughts

Leave a reply

ExcelDemy
Logo