PDA

View Full Version : Sleeper: Delete a macro



lior03
07-15-2005, 12:17 PM
hello
the following macro run a specific macro from a list
on a worksheet.
how can i add a msgbox to tell the user he chose a wrong name.
secondly , is ther a way to delete a macro from the vba
editor.namely if i can run it can i delete it.
thanks


Sub testers2()
On Error GoTo canceled:
Dim y As String
y = InputBox("select macro to run ", "a macro runner")
With Application
.Run y
End With
canceled:
End Sub

mdmackillop
07-15-2005, 12:43 PM
Part 1

Sub testers1()
On Error GoTo canceled:
Dim y As String
y = InputBox("select macro to run ", "a macro runner")
On Error GoTo ErrH
Application.Run y
exit sub
ErrH:
MsgBox "Macro " & y & " not found."
canceled:
End Sub

Part 2 (a bit more involved)
http://www.vbaexpress.com/kb/getarticle.php?kb_id=250
Regards,
MD

Bob Phillips
07-15-2005, 01:09 PM
is ther a way to delete a macro from the vba
editor.namely if i can run it can i delete it.




Const vbext_pk_Proc = 0

Sub DeleteProcedure()
Dim oCodeModule As Object
Dim iStart As Long
Dim cLines As Long
Set oCodeModule = ThisWorkbook.VBProject.VBComponents("Module1").CodeModule
With oCodeModule
On Error GoTo dp_err:
iStart = .ProcStartLine("myProc", vbext_pk_Proc)
cLines = .ProcCountLines("myProc", vbext_pk_Proc)
.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