PDA

View Full Version : avoide an error



lior03
01-12-2006, 02:17 AM
hello
how can i avoide an error nesage in the following macro?
Sub coutjohn()
Dim MyCodeMod
Dim x As String
x = InputBox("how many lines of code")
Set MyCodeMod = ActiveWorkbook.VBProject. _
VBComponents(x).CodeModule
MsgBox " your module have " & MyCodeMod.CountOfLines & " lines of code"
If MyCodeMod Is Nothing Then
MsgBox (x) & " do not exist,please try again"
End If
End Sub

i want excel to tell me a module which name i enter does not exist.
another example is

Sub testers2()
Dim y As String
y = InputBox("select macro to find: ", "a macro finder", Default:="enter procedure name please:")
If y = Empty Then Exit Sub
On Error GoTo ErrH
Application.Goto y
MsgBox "Macro " & y & " found. ", 64
Exit Sub
ErrH:
MsgBox "Macro " & y & " not found. ", 48
End Sub


despite the error handler i keep getting an error message (error 1004).
thanks

OBP
01-12-2006, 04:20 AM
One way to do it is to turn off "Break On Error" and include in your error handling something like
If err = 1004 then MsgBox "Macro " & y & " not found. ", 48