在VBA控制下运行编辑器时,陷阱VBE编译错误 [英] Trap VBE compile error when running editor under VBA control

查看:53
本文介绍了在VBA控制下运行编辑器时,陷阱VBE编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在VB控制下运行excel VBA时,编译错误会打开VBE窗口,标记有问题的行并在消息框处停止.我想在执行这些操作之前捕获此类错误.

When running excel VBA under VB control a compile error opens the VBE window, flags the offending line and stops with a message box. I would like to trap such errors before these actions occur.

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

推荐答案

这是对我有用的代码.如果编译成功运行,则运行后将不会启用编译命令.运行编译时打开以取消显示警报."Application.DisplayAlerts"设置为FALSE无效.

This is the code that works for me. If the compilation is run successfully the compilation command will not be enabled after running. Open to suppress the alert when compilation is run. "Application.DisplayAlerts" set to FALSE did not work.

Sub CompileWorkbook()
    Dim objVBECommandBar As Object
    Set objVBECommandBar = Application.VBE.CommandBars
    Dim compileMe As CommandBarButton
    Set compileMe = objVBECommandBar.FindControl(Type:=msoControlButton, ID:=578)
    If compileMe.Enabled = True Then compileMe.Execute
    If compileMe.Enabled = True Then Debug.Print "Error Compiling"
End Sub

这篇关于在VBA控制下运行编辑器时,陷阱VBE编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆