Ajouter une référence de bibliothèque au projet VBA dans le classeur
Contents
[
Hide
]
Dans Microsoft Excel, vous pouvez ajouter une référence de bibliothèque au projet VBA en cliquant sur leOutils > Références… manuellement. Il ouvrira la boîte de dialogue suivante qui vous aidera à sélectionner parmi les références existantes ou à parcourir vous-même votre bibliothèque.
Mais parfois, vous devez ajouter ou enregistrer la référence de bibliothèque au projet VBA via le code. Vous pouvez le faire en utilisant Aspose.CellsVbaProject.getReferences().addRegisteredReference() méthode.
Ajouter une référence de bibliothèque au projet VBA dans le classeur
L’exemple de code suivant ajoute ou enregistre deux références de bibliothèque au projet VBA du classeur à l’aideVbaProject.getReferences().addRegisteredReference() méthode.
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"); | |