Agregar una referencia de biblioteca al proyecto VBA en el libro
En Microsoft Excel, puede agregar una referencia de biblioteca al proyecto VBA haciendo clic manualmente en Herramientas > Referencias…. Se abrirá el siguiente cuadro de diálogo que le ayudará a seleccionar entre las referencias existentes o explorar su propia biblioteca.
Pero a veces, necesita agregar o registrar la referencia de biblioteca al proyecto VBA a través del código. Puede hacerlo usando el método de Aspose.Cells VbaProject.getReferences().addRegisteredReference().
Cómo agregar una referencia de biblioteca al proyecto VBA en el libro
El siguiente código de muestra agrega o registra dos referencias de biblioteca al proyecto VBA del libro usando el método VbaProject.getReferences().addRegisteredReference().
// 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"); |