VbaModule class

Represents the module in VBA project.

public class VbaModule


Name Description
Codes { get; set; } Gets and sets the codes of module.
Name { get; set; } Gets and sets the name of Module.
Type { get; } Gets the type of module.



//Instantiating a Workbook object
Workbook workbook = new Workbook();
 // Init VBA project.
VbaProject vbaProject = workbook.VbaProject; 
// Add a new module.
int index = vbaProject.Modules.Add(VbaModuleType.Class, "test");
// Get vba module
VbaModule vbaModule = vbaProject.Modules[index];
// Set codes
vbaModule.Codes = "Sub ShowMessage()\r\nMsgBox \"Welcome to Aspose!\"\r\nEnd Sub";
//Saving the Excel file

 [Visual Basic]

'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Init VBA project.
Dim vbaProject as VbaProject  = workbook.VbaProject
'Add a new module.
Dim index as Integer = vbaProject.Modules.Add(VbaModuleType.Class, "test")
'Get vba module
Dim vbaModule as VbaModule = vbaProject.Modules(index)
'Set codes
vbaModule.Codes = "Sub ShowMessage()\r\nMsgBox \"Welcome to Aspose!\"\r\nEnd Sub"
'Saving the Excel file

See Also