Follow this article to remove Excel macros using C#. It has all the necessary details to set the IDE for development, a step-by-step procedure to write the application, and a sample code to delete Excel Vba using C#. It will guide you to access different properties of VBA modules and remove all or selected modules as per the requirements.
Steps to Remove Macros from Excel using C#
- Set the environment to use Aspose.Cells for .NET to delete macros
- Instantiate the license to avoid the watermark and other limitations
- Load the workbook containing the VBA code
- Iterate through all the modules to get information about all the modules in the workbook
- Access the collection of modules in the VbaProject class
- Call the Remove() method by passing the module name to be removed
- Save the output Excel file as an XLSM file
These steps explain the process to delete VBA project in Excel using C#. Load the license for full product features, load the input Excel file with VBA Project and modules in it, and parse through all to check various properties of each module. Once the module names are known, call the Remove() method with the module name in the Modules collection class to remove the module code from the VBA Project.
Code to Delete Excel Macros using C#
This sample code demonstrates the process to remove Excel macros. You have the option to remove an individual module by using its name or index. If you want to remove all the modules from a worksheet, pass the worksheet reference to the remove method, and for deleting all the VBA modules in a Workbook, call the Clear() method as shown in the commented code in the sample given above.
This article has guided us to access and remove VBA modules. To add or modify an existing VBA Module, refer to the article on Modify Excel VBA library using C#.