View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Delete All Macros

Hi Rob,

You need to set a reference the visual Basic Extensibility library:

VBA Menu | Tools | References


---
Regards,
Norman



"Rob" wrote in message
...
I have a workbook that contains several macros that manipulate and
calculate
data for billing to be sent to a client. After all calculations are
performed, I will be copying a pasting the worksheets to themselves as
values
only so that the client will not be able to see the formulas. Afterwards,
I
would like to delete all the macros as well. I found the following code
through the discussion group:

Sub DeleteAllVBA()

Dim VBComp As VBIDE.VBComponent
Dim VBComps As VBIDE.VBComponents

Set VBComps = ActiveWorkbook.VBProject.VBComponents

For Each VBComp In VBComps
Select Case VBComp.Type
Case vbext_ct_StdModule, vbext_ct_MSForm, _
vbext_ct_ClassModule
VBComps.Remove VBComp
Case Else
With VBComp.CodeModule
.DeleteLines 1, .CountOfLines
End With
End Select
Next VBComp

End Sub


However, when I try to run this macro, I get an error message at the very
first line that says:

Compile Error:

User defined type not defined

Obviously I would like to know what to change and how to delete all the
macros, including the one that is being written to delete the macros.

Can anyone help?