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
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
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.
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.Aspose.Pdf.23.12.dll).If the reference does not appear, browse to the generated type‑library file (Aspose.Pdf.tlb) and add it manually.
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
CreateObject("Aspose.Pdf.Document") (early binding works as well if you added the reference).MSXML2.XMLHTTP or WinHttp.WinHttpRequest).regasm … /codebase /tlb as Administrator.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.
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: