在工作簿中为VBA项目添加库引用
Contents
[
Hide
]
有时候,您需要通过代码添加或注册VBA项目的库引用。可以使用Aspose.Cells for Python via .NET中的VbaProject.references.add_registered_reference()方法完成此操作。
在Microsoft Excel中为VBA项目添加库引用
在Microsoft Excel中,您可以通过手动点击**工具 > 引用…**来添加VBA项目的库引用。
使用Aspose.Cells在工作簿中为VBA项目添加库引用
以下示例代码使用VbaProject.references.add_registered_reference()方法向工作簿的VBA项目添加或注册了两个库引用。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |