Macro to delete Macro

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

Guest

I want to create a macro X that will delete another macro Y - assume macro X
is stored in the Personal Macro Workbook & macro Y is stored in the currently
active workbook. What is the code to delete a macro?
 
Here is some code that deletes myProc from Module1

Sub DeleteProcedure()
Const vbext_pk_Proc = 0
Dim oCodeModule As Object
Dim iStart As Long
Dim cLines As Long

Set oCodeModule =
ThisWorkbook.VBProject.VBComponents("Module1").CodeModule
With oCodeModule
iStart = .ProcStartLine("myProc", 0)
cLines = .ProcCountLines("myProc", 0)
.DeleteLines iStart, cLines
End With

End Sub


--

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