Home>Blogs>VBA>Automatic Invoice in Excel VBA: One Click to PDF (Step by Step)
VBA

Automatic Invoice in Excel VBA: One Click to PDF (Step by Step)

This tutorial builds an automatic invoice in Excel VBA. You pick an order number, click one button, and the macro fills the invoice, blocks duplicates, adds sales tax and shipping, numbers the invoice, saves a PDF and logs it. The example business is a fictional office supply company in Columbus, Ohio.

Automatic invoice in Excel VBA tutorial
Automatic invoice in Excel VBA tutorial

⬇️  Join Free on Skool & Download the Practice File
Free membership · takes 1 minute · the file is in Classroom → Free Downloads from YouTube.

To learn VBA step by step, join Excel VBA Basics with AI on Next Gen Templates Academy. Code BF40 gives 40% off until 1 December 2026, 23:59 IST.

Frequently asked questions

Can Excel create an invoice automatically?

Yes. A short VBA macro can read the order number, copy the order lines and customer details, calculate tax and shipping, number the invoice and save it as a PDF.

How does the macro stop duplicate invoices?

Before it builds anything, it searches the Invoice Log for the order number with Range.Find. If the order is already there, it shows the existing invoice number and stops.

Why does the PDF save fail from a OneDrive folder?

ThisWorkbook.Path returns a web address for a synced OneDrive file. The macro checks for that and saves to your Documents folder instead.

How many lines can one invoice hold?

This layout has twelve line rows. The macro warns you if an order has more, so you can add rows to the invoice first.

Why use WorksheetFunction.Round instead of Round?

The VBA Round function uses banker’s rounding. WorksheetFunction.Round rounds the same way the ROUND formula does on the sheet.

Do I need to save the file as xlsm?

Yes. A normal xlsx workbook cannot keep macros, so save it as an Excel macro-enabled workbook.

Download the free practice file

The zip holds the practice workbook, the solution workbook and the code module.

⬇️  Join Free on Skool & Download the Practice File
Free membership · takes 1 minute · the file is in Classroom → Free Downloads from YouTube
Practice file, solution workbook and the VBA code · .zip

Conclusion

One macro now handles the whole invoice: it checks the log, builds the page, calculates the money, saves the PDF and records it. Change the constants and the sheet layout to match your own business.

PK
Meet PK, the founder of PK-AnExcelExpert.com! With over 15 years of experience in Data Visualization, Excel Automation, and dashboard creation. PK is a Microsoft Certified Professional who has a passion for all things in Excel. PK loves to explore new and innovative ways to use Excel and is always eager to share his knowledge with others. With an eye for detail and a commitment to excellence, PK has become a go-to expert in the world of Excel. Whether you're looking to create stunning visualizations or streamline your workflow with automation, PK has the skills and expertise to help you succeed. Join the many satisfied clients who have benefited from PK's services and see how he can take your Excel skills to the next level!
https://www.pk-anexcelexpert.com