如果输入框的答案是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
答案 0 :(得分: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
这样您的用户(或您)就不必输入“是”或“否”以继续/结束流程。
答案 1 :(得分: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