Add a library reference to VBA project in workbook

Add a library reference to VBA project in Microsoft Excel

In Microsoft Excel, you can add a library reference to the VBA project by clicking the Tools > References… manually.

Add a library reference to the VBA project in a workbook using Aspose.Cells

The following sample code adds or registers two library references to the VBA project of the workbook using VbaProject.references.add_registered_reference() method.

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
dataDir = RunExamples.GetDataDir(".")
outputPath = dataDir + "Output_out.xlsm"
workbook = Workbook()
vbaProj = workbook.vba_project
vbaProj.references.add_registered_reference("stdole", "*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\system32\\stdole2.tlb#OLE Automation")
vbaProj.references.add_registered_reference("Office", "*\\G{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}#2.0#0#C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE14\\MSO.DLL#Microsoft Office 14.0 Object Library")
workbook.save(outputPath)