Manage VBA code of Excel Macro‑Enabled workbook.

Add a VBA Module in C#

The following sample code creates a new workbook, adds a new VBA module and macro code, and saves the output in the XLSM format. When you open the output XLSM file in Microsoft Excel and click the Developer > Visual Basic menu commands, you will see a module named TestModule and inside it, you will see the following macro code.

 Sub ShowMessage()

    MsgBox "Welcome to Aspose!"

End Sub

Here is the sample code to generate the output XLSM file with a VBA module and macro code.

Modify VBA or Macro in C#

The following sample code loads the source Excel file which has the following VBA or macro code inside it:

 Sub Button1_Click()

    MsgBox "This is test message."

End Sub

After executing the Aspose.Cells sample code, the VBA or macro code will be modified as follows:

 Sub Button1_Click()

    MsgBox "This is Aspose.Cells message."

End Sub

You can download the source Excel file and the output Excel file from the given links.

Advanced topics