Delete Modules in Macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The macro recorder does not record the mouse clicks to Delete a Module.

How can I delete modules via a macro?

Thanks,
Mark
 
Mark,

Here is an example for Module2

Dim VBComp As Object

Set VBComp = ThisWorkbook.VBProject.vbcomponents("Module2")
ThisWorkbook.VBProject.vbcomponents.Remove VBComp

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
I'd like to remove all the modules in a workbook.

Would you have some sample code to iterate through the modules within a
workbook?

Thank you - your posts are very helpful.

Mark
 
Mark,

This will remove all modules. You cannot remove Sheet or Thisworkbook
modules.

Dim VBComp As Object
Dim vbMod As Object

For Each vbMod In ThisWorkbook.VBProject.vbcomponents
If vbMod.Type = 1 Then ' a module
ThisWorkbook.VBProject.vbcomponents.remove vbMod
End If
Next vbMod


--

HTH

RP
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top