Aspose .pdf use in excel vba

Can I use Aspose .pdf in excel vba code?
I’ve installed the package but I don’t see any References in the References - VBA Project dialog box.

Thanks, Matt

@MNorth

Yes – you can call Aspose.PDF for .NET from Excel VBA, but the library is not added automatically to the VBA References list. You have to expose the .NET assembly as a COM component and then reference it manually.

1. Register the Aspose.PDF assembly for COM

rem Open a Developer Command Prompt (run as Administrator)
cd "C:\Program Files\Aspose\PDF\Aspose.Pdf.dll"   ← path to the DLL you installed
regasm Aspose.Pdf.dll /codebase /tlb
  • regasm creates the COM type library (.tlb) and registers the assembly in the Windows Registry.
  • Use the exact path to the version you installed (e.g., Aspose.Pdf.23.12.dll).

2. Add the reference in VBA

  1. Open Excel → Alt + F11 (VBA editor).
  2. Choose Tools > References….
  3. Scroll down and check Aspose.Pdf (or the name that appears, e.g., Aspose.Pdf 23.12).
  4. Click OK.

If the reference does not appear, browse to the generated type‑library file (Aspose.Pdf.tlb) and add it manually.

3. Sample VBA code

Sub CreatePdf()
    Dim doc As Object               ' late‑bound COM object
    Set doc = CreateObject("Aspose.Pdf.Document")

    ' add a page and some text
    Dim page As Object
    Set page = doc.Pages.Add()
    Dim txt As Object
    Set txt = page.Paragraphs.Add()
    txt.Text = "Hello from Excel VBA!"

    ' save the PDF
    doc.Save "C:\Temp\HelloFromVBA.pdf"
End Sub
  • Use CreateObject("Aspose.Pdf.Document") (early binding works as well if you added the reference).
  • All regular Aspose.PDF API members are available through the COM wrapper.

4. Alternatives

  • Aspose.PDF Cloud – if you prefer not to deal with COM registration, you can call the REST API from VBA (via MSXML2.XMLHTTP or WinHttp.WinHttpRequest).
  • Aspose.Cells – the same approach (register COM, add reference) is documented for other Aspose products, so the steps above are consistent across the suite.

Quick checklist

  • [ ] .NET runtime (≥ 4.6) installed.
  • [ ] Run regasm … /codebase /tlb as Administrator.
  • [ ] Add the COM reference in the VBA editor.
  • [ ] Use CreateObject("Aspose.Pdf.Document") (or early‑bound types) in your VBA code.

Once the assembly is registered, the reference will stay available for any workbook that needs to work with PDFs. If you still don’t see the reference after registration, double‑check the DLL path and that you used the same bitness (32‑bit Excel ↔ 32‑bit DLL, 64‑bit Excel ↔ 64‑bit DLL).

when I try to run the regasm command, if get the following:

C:\Program Files (x86)\Aspose\Aspose.PDF for .NET\Bin\net7.0>regasm Aspose.Pdf.dll /codebase /tlb
Microsoft .NET Framework Assembly Registration Utility version 4.8.9037.0
for Microsoft .NET Framework version 4.8.9037.0
Copyright (C) Microsoft Corporation. All rights reserved.

RegAsm : error RA0000 : Could not load file or assembly ‘System.Net.WebHeaderCollection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The system cannot find the file specified.

@MNorth

Please try to download .NET 4.x specific DLLs from the link below and register using regasm command. In case issue still persists, please let us know: