【问题标题】:VBA Excel Msgbox If statement for actionVBA Excel Msgbox If 语句用于操作
【发布时间】:2020-02-27 14:38:28
【问题描述】:

我想运行我的 msgBox 即,单击“是”后,我想删除两件事。

我在这里找到了一些解决方案:

MsgBox Yes/No Excel VBA

Excel VBA vbYesNo MsgBox

并尝试做一些有效的事情。 我的代码如下所示:

   Case "Remove"

        MsgBox "Do you want to remove all firestopping elements with their values?", 
        vbQuestion + vbYesNo
        If MsgBox(Question) = vbYes Then
        Sheets("hilti firestopping stores").Range("E5:E17").ClearContents
        Call ActiveShapes

        End If

...

   Sub Firestopshapes()
   Dim shp As Shape
   Dim Ws As Worksheet

   Set Ws = ActiveSheet
   For Each shp In Ws.Shapes
    If shp.Name = "Firestop" Then
        shp.Delete
    End If
  Next shp
 End Sub

结果如下图:

我还将If MsgBox(Question) = vbYes ThenIf ans = vbYes Then 互换了,但我得到了一个错误。

有什么方法可以让这个 msgbox 运行吗?

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    也许这更清楚:

    Dim ans as VbMsgBoxResult
    ans = MsgBox("Do you want to remove all firestopping elements with their values?", _
        vbQuestion + vbYesNo)
    
    If ans = vbYes Then
         ...
    End If
    

    【讨论】:

    • 简单明了
    猜你喜欢
    • 1970-01-01
    • 2020-07-18
    • 2017-11-30
    • 2018-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多