在子VBA中停用msgbox

时间:2017-09-08 11:33:01

标签: vba excel-vba subroutine msgbox excel

Sub prelim()
    MsgboX "Hello World"
End Sub


Sub Main()
    Call prelim
End Sub

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

1 个答案:

答案 0 :(得分:6)

如果不更改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