Manage VBA codes of Visio Macro-Enabled diagram.
Add a VBA Module
The following sample code adds a new VBA Module and Macro Code and saves the output in the VSDM format. Once, you will open the output VSDM file in Microsoft Visio 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 VSDM file with VBA Module and Macro Code.
Modify VBA or Macro
You can modify VBA or Macro Code using Aspose.Diagram. Aspose.Diagram has added the following namespace and classes to read and modify the VBA project in the Visio file.
This article will show you how to change the VBA or Macro Code inside the source Visio file using Aspose.Diagram.
The following sample code loads the source Visio 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.Diagram sample code, the VBA or Macro code will be modified like this
Sub Button1_Click() MsgBox "This is Aspose.Diagram message." End Sub