pjawynn
06-19-2015, 05:55 AM
Good Afternoon, would someone be able to help with a VBA question I have concerning a outlook mail item. We receive a automated mail from our online store which includes purchases for items. One of the questions is "Are you a resident in a halls of residence?:" to which the response is either "Yes" or "No" defined by the website. I need for the macro to identify if the response to the question is "Yes" then a message box appears asking if the user wants to proceed.
I have been working on the following code and tweaking it, but every time it just comes up with the response message box "Did not Work", yet if I trim the response into an excel cell "Yes" is displayed correctly.
Any help would be much appreciated as I cannot find a solution when searching.
-----------------
Dim olItem As Outlook.MailItem
Dim vText As Variant
Dim sText As String
Dim vItem As Variant
Dim Hallsitem As String
Dim HRItem As String
Dim i As Long
If Application.ActiveExplorer.Selection.Count = 0 Then
MsgBox "No Items selected!", vbCritical, "Error"
Exit Sub
End If
For Each olItem In Application.ActiveExplorer.Selection
sText = olItem.Body
vText = Split(sText, Chr(13))
HRItem = "Yes"
If InStr(1, vText(i), "Are you a resident in a halls of residence?:") > 0 Then
vItem = Split(vText(i), Chr(58))
Hallsitem = Trim(vItem(1))
End If
If Hitem = HRItem Then
MsgBox ("Worked")
Else
MsgBox ("Did not Work")
End If
Next olItem
'PermitAppFrm.Show
End Sub
------------------
Thank you
Pjawynn
I have been working on the following code and tweaking it, but every time it just comes up with the response message box "Did not Work", yet if I trim the response into an excel cell "Yes" is displayed correctly.
Any help would be much appreciated as I cannot find a solution when searching.
-----------------
Dim olItem As Outlook.MailItem
Dim vText As Variant
Dim sText As String
Dim vItem As Variant
Dim Hallsitem As String
Dim HRItem As String
Dim i As Long
If Application.ActiveExplorer.Selection.Count = 0 Then
MsgBox "No Items selected!", vbCritical, "Error"
Exit Sub
End If
For Each olItem In Application.ActiveExplorer.Selection
sText = olItem.Body
vText = Split(sText, Chr(13))
HRItem = "Yes"
If InStr(1, vText(i), "Are you a resident in a halls of residence?:") > 0 Then
vItem = Split(vText(i), Chr(58))
Hallsitem = Trim(vItem(1))
End If
If Hitem = HRItem Then
MsgBox ("Worked")
Else
MsgBox ("Did not Work")
End If
Next olItem
'PermitAppFrm.Show
End Sub
------------------
Thank you
Pjawynn