VBA msgBox - vbYes 不断调用错误的 sub

VBA msgBox - vbYes keeps calling wrong sub

如果我单击“是”,VBA 继续转到功能授权?我做错了什么?

Public AutoDate As Date
Public NewDate As String

Public Sub GetDate()  ' DATUM BEPALEN
    AutoDate = Date - 1
    MsgBox (AutoDate), (vbYesNo), ("Datum")
    Dim Response As VbMsgBoxResult
        If Response = vbYes Then
            NewDate = AutoDate
            Call DeleteDate
        Else    ' No
            Call ManDate
        End If
End Sub

您还没有将 MsgBox 的结果分配给 Response。
也不确定 VbMsgBoxResult 在该实例中是否是有效数据类型。

尝试以下任一方法:

Public Sub GetDate()  ' DATUM BEPALEN

    AutoDate = Date - 1

    If MsgBox(AutoDate, vbYesNo, "Data") = vbYes Then
        NewDate = AutoDate
        Call DeleteDate
    Else    ' No
        Call ManDate
    End If

End Sub

Public Sub GetDate()  ' DATUM BEPALEN

        Dim Response As Long

        AutoDate = Date - 1
        Response = MsgBox(AutoDate, vbYesNo, "Data")

        If Response = vbYes Then
            NewDate = AutoDate
            Call DeleteDate
        Else    ' No
            Call ManDate
        End If

    End Sub

您需要将 Response 检索为 MsgBox 函数的 return:

Dim Response as Integer
Response= MsgBox( AutoDate, vbYesNo, "Datum")

现在您可以通过 if-test Response 来决定要做什么。

您需要一个变量来捕获响应...

Dim ans As Integer
ans = MsgBox("hello", vbYesNo, "Datum")
If ans = vbYes Then
   MsgBox "Yes"
Else
   MsgBox "No"
End If