简体   繁体   English

如何抑制来自 VB6 的 excel 编译器错误

[英]How to suppress excel compiler error from VB6

I am executing the Excel 'Debug -> Compile VBAProject' from a VBA project like below,我正在从如下所示的 VBA 项目中执行 Excel 'Debug -> Compile VBAProject',

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.".在这里运行.Execute ,Excel VBA 抛出错误“编译器错误:未定义用户定义的类型。”。

But actually I want to suppress this Excel VBA error.但实际上我想抑制这个 Excel VBA 错误。 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.也许我怀疑的是,由于.Execute被成功调用(调用 Debug->Compile VBAProject),无论是否有任何错误,它都会返回成功,而不是去错误处理程序。

Is there anyway, I can suppress the Excel VBA compiler error.无论如何,我可以抑制 Excel VBA 编译器错误。

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.当您将点击发送到 Compile 按钮时,如果该按钮不可用,则会出现错误,如果您刚刚编译了一些东西。 That error you can catch and suppress.您可以捕获并抑制该错误。 If there is a compilation error, you won't be able to catch it this way.如果存在编译错误,您将无法通过这种方式捕获它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM