Using a macro to remove a macro

P

PCLIVE

I have this macro (below) that I would like to remove using another macro.
It is located in 'ThisWorkbook'.

Private Sub Workbook_Open()

What code can I use in a Macro to remove 'Private Sub Workbook_Open()'?

Thanks,
Paul
 
B

Bob Phillips

'----------------------------------------------------------------
Sub DeleteProcedure()
'----------------------------------------------------------------
Dim oCodeModule As Object
Dim iStart As Long
Dim cLines As Long

Set oCodeModule =
ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
With oCodeModule
On Error GoTo dp_err:
iStart = .ProcStartLine("Workbook_Open", 0)
cLines = .ProcCountLines("Workbook_Open", 0)
.DeleteLines iStart, cLines
On Error GoTo 0
Exit Sub
End With

dp_err:
If Err.Number = 35 Then
MsgBox "Procedure does not exist"
End If
End Sub
 

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