Manage VBA codes of Excel Macro-Enabled workbook.

Add a VBA Module in Python

The following sample code creates a new workbook and adds a new VBA Module and Macro Code and saves the output in the XLSM format. Once, you will 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 VBA Module and Macro Code.

Modify VBA or Macro in Python

The following sample code loads the source Excel file which has a following VBA or Macro code inside it

 Sub Button1_Click()

    MsgBox "This is test message."

End Sub

After the execution of Aspose.Cells for Python via .NET sample code, the VBA or Macro code will be modified like this

 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.

Advance topics