【问题标题】:Deactivate msgbox in a sub VBA在子 VBA 中停用 msgbox
【发布时间】:2017-09-08 11:33:01
【问题描述】:
Sub prelim()
    MsgboX "Hello World"
End Sub


Sub Main()
    Call prelim
End Sub

在上面的代码中Sub prelim 不能被编辑。当我运行Sub prelim 时我想要msgbox,但是当我运行Sub Main 时我不想弹出消息框。怎么做?

【问题讨论】:

  • Application.DisplayAlerts = False'你的代码在这里`Application.ScreenUpdating = True
  • 试试上面的说法
  • 试过了。但它只适用于子外部。当我运行 prelim 时,我需要 msgbox 得到提示。但是当我运行 main 时,我不需要 msgbox。 ://

标签: vba excel subroutine msgbox


【解决方案1】:

如果不更改Sub prelim,这是不可能的

Sub prelim(Optional silent As Boolean = True)
    If Not silent Then MsgBox "Hello World"
End Sub


Sub Main()
    prelim True   'no msgbox
    prelim False  'with msgbox
    prelim        'no msgbx
End Sub

【讨论】:

  • 值得注意的是,Call 关键字已不再使用。虽然它会编译得很好,但最好只做prelim Trueprelim
  • @BrandonBarney 当然你是对的! Call 已弃用。我改变了。
猜你喜欢
  • 1970-01-01
  • 2020-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-08
  • 1970-01-01
相关资源
最近更新 更多