【发布时间】:2018-07-09 09:53:35
【问题描述】:
我正在尝试确保在每个阶段都将数据输入到 InputBox 中,否则我希望弹出消息并结束输入。
如果没有输入任何内容,我会弹出一个 MsgBox,但我想添加一个选项,让 Sub 保留在 InputBox 中,以便用户仍然可以输入数据。
我已经尝试vbRetryCancel 并且重试将循环然后永远不会取消(我必须强制 Outlook 关闭以结束宏)或者取消将循环并且永远不会重试。
如果我能做到,那么在输入数据或单击“取消”之前,InputBox 不会以“Ok”前进,这也可以,但如果没有输入任何内容来提醒用户,我仍然需要一个 MsgBox。
Sub Request_Tracking()
Dim objMsg As MailItem
Dim tasksource As String
Set objMsg = Application.CreateItem(olMailItem)
'requests input of the user with various options
tasksource = InputBox("Please select task receipt method:" & _
vbCrLf & vbTab & "1 - Phone call" & _
vbCrLf & vbTab & "2 - Email" & _
vbCrLf & vbTab & "3 - Instant Message" & _
vbCrLf & vbTab & "4 - Desk walk-up" & _
vbCrLf & vbTab & "5 - Miscellaneous", "Option Chooser")
'if response is blank then ends the task
If tasksource = vbNullString Then
MsgBox "Nothing was entered. Please re-enter your request.", vbOKOnly, "Error!"
Exit Sub
End If
Select Case tasksource
Case "1"
tasksource = "Phone call"
Case "2"
tasksource = "Email"
Case "3"
tasksource = "Instant Message"
Case "4"
tasksource = "Desk walk-up"
Case "5"
tasksource = "Miscellaneous"
Case Else
tasksource = tasksource
End Select
'various input boxes for data needed, if response is blank then ends the task without send
strName = InputBox("Requestor Name:")
If strName = vbNullString Then
MsgBox "Nothing was entered. Please reattempt your request.", vbOKOnly, "Error"
Exit Sub
End If
strCoreEvent = InputBox("Task Description:")
If strCoreEvent = vbNullString Then
MsgBox "Nothing was entered. Please reattempt your request.", vbOKOnly, "Error"
Exit Sub
End If
strUnitNum = InputBox("Number of units:")
If strUnitNum = vbNullString Then
MsgBox "Nothing was entered. Please reattempt your request.", vbOKOnly, "Error"
Exit Sub
End If
strTime = InputBox("Processing Time:")
If strTime = vbNullString Then
MsgBox "Nothing was entered. Please reattempt your request.", vbOKOnly, "Error"
Exit Sub
End If
'configures message being sent, sents to WFM box and formats the body font and various line breaks and then sends
With objMsg
.To = "tracking@test.com"
.Subject = "Request Received"
.HTMLBody = "<body style=font-size:11pt;font-family:Arial><b>For request tracking; please assign to me.</b>" & "<p>" & tasksource & " request from " & strName & ": " & strCoreEvent & "<br />Number of units: " & strUnitNum & "<br />Processing time: " & strTime & "</p></body>"
.Recipients.ResolveAll
.Send
End With
End Sub
【问题讨论】:
-
是否强制用户在输入框中输入数据?
-
@PankajJaju 是的,我愿意。我不确定如何做到这一点的最简单方法
标签: vba outlook outlook-2010