In this article we will create a macro to delete module from the workbook.
We will be using the MainModule as raw module.
We want to get rid of this MainModule.
Click on this button for the same.
In this article, we have created two macros, DeleteVBComponent and calling_procedure.
It takes the workbook name and module name as inputs, and deletes the module from the workbook.
It is used to call the DeleteVBComponent macro with the active workbook and MainModule as inputs.
Application.DisplayAlerts = False
This code is used to disable the alert message.
This code is used to remove the module from the workbook.
Application.DisplayAlerts = True
This code is used to enable the alert message.
Please follow below for the code
Option Explicit Sub DeleteVBComponent(ByVal wb As Workbook, ByVal CompName As String) 'Disabling the alert message Application.DisplayAlerts = False 'Ignore errors On Error Resume Next 'Delete the component wb.VBProject.VBComponents.Remove wb.VBProject.VBComponents(CompName) On Error GoTo 0 'Enabling the alert message Application.DisplayAlerts = True End Sub Sub calling_procedure() 'Calling DeleteVBComponent macro DeleteVBComponent ActiveWorkbook, "MainModule" End Sub
We would love to hear from you, do let us know how we can improve our work and make it better for you. Write to us at email@example.com
The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.