在工作簿中添加对 VBA 项目的库引用
Contents
[
Hide
]
在 Microsoft Excel 中,您可以通过单击**工具 > 参考…**手动。它将打开以下对话框,帮助您从现有参考文献中进行选择或自行浏览您的图书馆。
但有时,您需要通过代码向 VBA 项目添加或注册库引用。您可以使用 Aspose.Cells 来完成[VbaProject.getReferences().addRegisteredReference()](https://reference.aspose.com/cells/java/com.aspose.cells/vbaprojectreferencecollection#addRegisteredReference(java.lang.String,%20java.lang.String)) 方法。
在工作簿中添加对 VBA 项目的库引用
下面的示例代码添加或注册两个库引用到工作簿的 VBA 项目使用[VbaProject.getReferences().addRegisteredReference()](https://reference.aspose.com/cells/java/com.aspose.cells/vbaprojectreferencecollection#addRegisteredReference(java.lang.String,%20java.lang.String)) 方法。
This file contains 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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddLibraryReference.class); | |
Workbook workbook = new Workbook(); | |
VbaProject vbaProj = workbook.getVbaProject(); | |
vbaProj.getReferences().addRegisteredReference("stdole", | |
"*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\system32\\stdole2.tlb#OLE Automation"); | |
vbaProj.getReferences().addRegisteredReference("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(dataDir + "output.xlsm"); | |