ERLANDSEN DATA CONSULTING Excel & VBA Tips   Informasjon på norsk / Information in Norwegian

These pages are no longer updated and are only available for archive purposes.

Click here to visit the pages with updated information.

Delete a module

When you want to delete a module by code, you can use the macro below:

Sub DeleteVBComponent(ByVal wb As Workbook, ByVal CompName As String)
' requires a reference to the Microsoft Visual Basic Extensibility library
' deletes the vbcomponent named CompName from wb
    Application.DisplayAlerts = False
    On Error Resume Next ' ignores any errors
    wb.VBProject.VBComponents.Remove wb.VBProject.VBComponents(CompName) 
    ' delete the component
    On Error GoTo 0
    Application.DisplayAlerts = True
End Sub

Example:

DeleteVBComponent ActiveWorkbook, "TestModule"

 

Document last updated 2000-02-05 12:51:07      Printerfriendly version

 

Erlandsen Data Consulting     http://www.erlandsendata.no/   
Excel & VBA Tips   Copyright ©1999-2024    Ole P. Erlandsen   All rights reserved
E-mail Contact Address