ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete Modules in Macro (https://www.excelbanter.com/excel-programming/324679-delete-modules-macro.html)

Mark

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

How can I delete modules via a macro?

Thanks,
Mark

Dave Peterson[_5_]

Delete Modules in Macro
 
Visit Chip Pearson's site to find out how:
http://www.cpearson.com/excel/vbe.htm

Mark wrote:

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

How can I delete modules via a macro?

Thanks,
Mark


--

Dave Peterson

Bob Phillips[_6_]

Delete Modules in Macro
 
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)


"Mark" wrote in message
...
The macro recorder does not record the mouse clicks to Delete a Module.

How can I delete modules via a macro?

Thanks,
Mark




Mark

Delete Modules in Macro
 
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

"Bob Phillips" wrote:

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)


"Mark" wrote in message
...
The macro recorder does not record the mouse clicks to Delete a Module.

How can I delete modules via a macro?

Thanks,
Mark





Bob Phillips[_6_]

Delete Modules in Macro
 
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)


"Mark" wrote in message
...
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

"Bob Phillips" wrote:

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)


"Mark" wrote in message
...
The macro recorder does not record the mouse clicks to Delete a

Module.

How can I delete modules via a macro?

Thanks,
Mark








All times are GMT +1. The time now is 11:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com