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 module content

It's not possible to delete all kinds of modules, you can't delete the codemodules for worksheets, charts and ThisWorkbook. In these modules you have to delete the content instead of the module itself:

Sub DeleteModuleContent(ByVal wb As Workbook, _
    ByVal DeleteModuleName As String)
' requires a reference to the Microsoft Visual Basic Extensibility library
' deletes the contents of DeleteModuleName in wb
' use this if you can't delete the module
    On Error Resume Next
    With wb.VBProject.VBComponents(DeleteModuleName).CodeModule
        .DeleteLines 1, .CountOfLines
    End With
    On Error GoTo 0
End Sub

Example:

DeleteModuleContent ActiveWorkbook, "Sheet1"

 

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

 

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