2017-03-07 13 views
0

次のコードがあり、YesNoCancelオプションは何もしません。私は何を間違えていますか?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 
+0

をチェックする必要があります。 'wb'は誰ですか? – BOB

+0

vbはすべて開いているワークブックであり、次のように定義されているように、forループ内に一時的な名前を格納します:For Each wb Application.Workbooks –

答えて

1

あなたは `wb`のための` set`を持っていない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 
+0

新規これはかなり明白でした。 –

関連する問題