VBA YesNoCancel未按预期工作

时间:2017-03-07 01:47:48

标签: vba

我有以下代码,YesNoCancel选项不做任何事情。我做错了什么?

Option Explicit

Sub wwb()

    'lists each book that's OPEN
    Dim wb As Workbook, ws As Workbook, wd As Workbook
    Set wd = ThisWorkbook
         MsgBox wd.Name
    Dim output As Integer
    Dim msgValue
    For Each wb In Application.Workbooks
        If wb.Name = wd.Name Then
            MsgBox "The destination WorkBook is :" & wd.Name
        Else
            output = MsgBox("Is " & wb.Name & " your source file to import data?", vbYesNoCancel, "Please confirm source file")
                If msgValue = vbYes Then
                    MsgBox "test yes"
                ElseIf msgValue = vbNo Then
                    MsgBox "test No"
                ElseIf msgValue = vbCancel Then
                    MsgBox "Test cancel"
                End If
        End If
    Next wb

End Sub

1 个答案:

答案 0 :(得分:1)

您需要检查output而不是msgValue

output = MsgBox("Is " & wb.Name & " your source file to import data?", vbYesNoCancel, "Please confirm source file")
        If output = vbYes Then
            MsgBox "test yes"
        ElseIf output = vbNo Then
            MsgBox "test No"
        ElseIf output = vbCancel Then
            MsgBox "Test cancel"
        End If
相关问题