VBA - Method to Detect Compilation Failure

守給你的承諾、 提交于 2020-01-06 08:14:27

问题


I have the following code:

Public Function Compiler()
    On Error GoTo ErrorHandler

    Compiler = "Successfully Compiled"

    Dim compileMe As Object
    Set compileMe = Application.VBE.CommandBars.FindControl(Type:=msoControlButton, ID:=578)

    If compileMe.Enabled Then
        compileMe.Execute
    End If

    Exit Function

ErrorHandler:

    Compiler = "Unable to Compile - " & Err.Description

End Function

It is very similar to the suggestion posted here, and it doesn't work. It you introduce errors into the rest of your application and run this, you will get "Successfully Compiled" every time (after clicking past the error messages).

Is there a way to have the method return "Unable to Compile" if the file cannot be compiled?

来源:https://stackoverflow.com/questions/55621735/vba-method-to-detect-compilation-failure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!