» Delete module content using VBA in Microsoft Excel
VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
CATEGORY - Modules, Class Modules in VBA
VERSION - All Microsoft Excel Versions
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)
' 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"
Book Store:
Recommended Books:
- The Fall of Advertising and the Rise of PR
- Microsoft Windows XP Step by Step (With CD-ROM)
- The One Page Business Plan: Start With a Vision, Build a Company!
- The Complete Book of Business Plans: Simple Steps to Writing a Powerful Business Plan (Small Business Sourcebooks)
- Essentials of Accounting and Post Test Booklet 8, Eighth Edition
- Word 2002: The Complete Reference
No comments have been submitted.

