VBA, delete all macro

G

Guest

Hi,

I have 3 macros in 1 module and 1 macro (before print) in the
"ThisWorkbook". Is there a way to delete all the macros automatically (with a
macro?!) in a workbook?

Thank you.
 
R

Ron de Bruin

Hi Danny

Copy this macro in Module1
If you run it it delete the whole module

Add code to delete the code in the thisworkbook where it say

'
' your code
'

See Chip's site
http://www.cpearson.com/excel/vbe.htm


Sub TheMacro()
'
' your code
'
With ThisWorkbook.VBProject.VBComponents
.Remove .Item("Module1")
End With
End Sub
 
C

Chip Pearson

Danny,

Try

With ActiveWorkbook.VBProject.VBComponents
.Remove .Item("Module1")
With .Item("ThisWorkbook").CodeModule
.DeleteLines 1, .CountOfLines
End With
End With

See www.cpearson.com/excel/vbe.htm for more info and examples.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

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

Top