1

如果输入框的答案是 ,我想运行一个宏yes

所以每次运行另一个宏时都需要问这个问题我需要问这个问题,直到用户在他们需要的所有日期完成宏。

我将输入框放在错误的位置,但不知道放在哪里。

Call ChangeDates

strMore = Application.InputBox(prompt:="Do you have any more dates to enter? Type Yes or No", Type:=2)

Do Until strMore = "no"

    If strMore = "yes" Then
        Call ChangeDates
    End If

    strMore = Application.InputBox(prompt:="Do you have any more dates to enter? Type Yes or No", Type:=2)
Loop
4

2 回答 2

1

考虑将此解决方案作为使用的替代方案InputBox

Sub test()  
Question:  
If MsgBox("Do you have any more dates to enter?", vbYesNo) = vbNo Then Exit Sub  
Call ChangeDates  
GoTo Question  

End Sub

这样您的用户(或您)就不必输入“是”或“否”来继续/结束该过程。

于 2013-10-05T22:13:20.940 回答
0

尝试这个

Sub Sample()
    Dim strMore

    Do Until strMore <> ""
        strMore = Application.InputBox(prompt:="Do you have any more dates to enter? Type Yes or No", Type:=2)

        '~~> Check if user pressed cancel or typed "NO"
        If strMore = False Or UCase(Trim(strMore)) = "NO" Then Exit Do

        '~~> Check if user entered "YES"
        If UCase(Trim(strMore)) = "YES" Then
            '~~> Rest of your code
            Call ChangeDates
        End If
    Loop
End Sub
于 2013-10-05T10:04:59.780 回答