Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am executing the Excel 'Debug -> Compile VBAProject' from a VBA project like below,

Public Function CheckForCompilerErrors()
    On Error GoTo compileerr    
    ExcelObject.ActiveWorkbook.VBProject.VBE.CommandBars.findcontrol(ID:=578).Execute
    Exit Function

compilerErr:
    MsgBox "Compilation failed. Give Debug->Compile VBAProject and fix the compilation errors."
End Function

Here after running the .Execute, Excel VBA is throwing the error "Compiler Error: User-defined type not defined.".

But actually I want to suppress this Excel VBA error. That's the reason why I added error handler. But in the above case, it is not going to error handler.

Maybe what I am suspecting is, since the .Execute got successfully called (which invokes Debug->Compile VBAProject) whether there is any error or not, it returns success and not going to error handler.

Is there anyway, I can suppress the Excel VBA compiler error.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
220 views
Welcome To Ask or Share your Answers For Others

1 Answer

When you are sending the click to the Compile button, there will be an error if the button is unavailable, which it is if you just compiled something. That error you can catch and suppress. If there is a compilation error, you won't be able to catch it this way.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...