XXLFormula AI
Pro ProjectFinanceIntermediateIncludes .xlsm

Invoice Generator

4.8· 3,610 learners

A complete billing macro: fills the invoice template, exports a client-ready PDF, sends it through late-bound Outlook (no reference required), and appends the record to the Invoice Register with timestamps and totals.

Learners
3,610
Duration
2 hours
Difficulty
Intermediate
Invoice Generator.xlsm — VBA EditorFileEditViewInsertFormatDebugRunToolsAdd-InsWindowHelpRun Sub/UserForm (F5)Project — VBAProjectVBAProject (Budget Automation.xlsm)Microsoft Excel ObjectsSheet1 (Transactions)Sheet2 (Dashboard)Sheet3 (Settings)ThisWorkbookFormsfrmCategoryEditorModulesmodBudgetmodChartsmodUtilsClass ModulesclsTransactionProperties — modBudget(Name)modBudget(General) ▾    RefreshBudget ▾1Option Explicit23' Budget refresh — one-click month-end.4Public Sub RefreshBudget()5    Dim wsData As WorksheetwsDash As Worksheet6    Dim lastRow As Longi As Long78    On Error GoTo Fail9    Application.ScreenUpdating = False1011    Set wsData = ThisWorkbook.Worksheets("Transactions")12    Set wsDash = ThisWorkbook.Worksheets("Dashboard")13    lastRow = wsData.Cells(wsData.Rows.Count"A").End(xlUp).Row1415    For i = 2 To lastRow16        Call AddToCategory(wsDash_17            CStr(wsData.Cells(i"C").Value), _18            CCur(wsData.Cells(i"D").Value))19    Next i2021    Application.ScreenUpdating = True22    MsgBox "Budget refreshed."vbInformation23    Exit Sub24Fail:25    Application.ScreenUpdating = True26    MsgBox "Failed: " & Err.DescriptionvbCritical27End SubImmediate — runningRefreshBudget?RefreshBudget › Loaded 218 transactions from 'Transactions' › Categories matched: 12 / 12 › Savings goals recalculated (6 goals) › Trend chart rebuilt in 42 ms Done. 0 errors, 0 warnings.ReadyLn 24, Col 5

Project screenshots

Code preview

Syntax-highlighted VBA — first 14 lines unlocked. Upgrade to view the full project.

invoice-generator.bas
VBA
1Option Explicit
2 
3' Invoice Generator — build a PDF invoice from the "Invoice" sheet
4' and email it to the client using late-bound Outlook.
5 
6Public Sub GenerateInvoice()
7 Dim ws As Worksheet
8 Dim invoiceNo As String, client As String, total As Currency
9 Dim pdfPath As String
10 
11 On Error GoTo Fail
12 Set ws = ThisWorkbook.Worksheets("Invoice")
13 
14 invoiceNo = NextInvoiceNumber()
15 ws.Range("F4").Value = invoiceNo
16 
17 client = CStr(ws.Range("B10").Value)
18 total = CCur(ws.Range("G40").Value)
19 
20 pdfPath = ThisWorkbook.Path & "\Invoices\" & invoiceNo & ".pdf"
21 EnsureFolder ThisWorkbook.Path & "\Invoices\"
22 
23 ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=pdfPath, _
24 Quality:=xlQualityStandard, IncludeDocProperties:=True, _
25 IgnorePrintAreas:=False, OpenAfterPublish:=False
26 
27 SendInvoiceEmail client, invoiceNo, total, pdfPath
28 LogInvoice invoiceNo, client, total, pdfPath
29 
30 MsgBox "Invoice " & invoiceNo & " emailed to " & client, vbInformation
31 Exit Sub
32Fail:
33 MsgBox "Invoice failed: " & Err.Description, vbCritical
34End Sub
Locked preview

Unlock XLFormula AI Pro to view the complete project source, download the .xlsm workbook, and generate custom VBA with AI.

Unlock with Pro

Key features

  • Automatic invoice numbering
  • PDF export at print quality
  • Late-bound Outlook — no reference setup
  • Invoice Register with searchable log
  • Configurable email template with placeholders

What's included

  • Invoice Generator.xlsm
  • PDF template & sample logos
  • Setup guide (PDF)
  • Register with 12 sample invoices
Included with Pro

Get this project — and every other one

Every download, every VBA project, every future release for $5.00/month.

  • AI VBA Generator
  • Download Projects
  • Complete VBA Library
  • Lifetime Updates
  • Premium Templates
  • Priority Support

Frequently asked questions

Do I need Outlook installed?
Yes — the mailer uses late-bound Outlook. A SMTP variant is included in the setup guide if Outlook isn't available.
Can I add my company logo?
Drop your logo into the header image placeholder — it resizes automatically.

Related projects