Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
227 views
in Technique[技术] by (71.8m points)

vba - How to suppress excel compiler error from VB6

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...