sunhux
asked on
Search for Outlook emails that need my action
I get hundreds of Outlook (version 2010 is what I use) emails per day but in most cases, the emails
don't need any action from me.
However, emails which require inputs/actions from me usually contains in the first 1-5 lines of it's
message body the following:
a) "Hi Pete" (more than 95% of the cases)
b) "Pete"
c) "Hello Pete"
Q1:
If I press Shift-Ctrl-F to search in the "message header & body", what should I type in as the search
keyword? Is it "Hi Pete" (ie with the double quotes to enclose it) or simply Hi Pete (without double
quotes)?
Q2:
is there any way I can perform a search of Outlook on only the first 5 lines of the message content
to search for the keyword "Pete"?
Q3:
Is there any way to be auto-notified if an email contain the word "Pete" in its message body were
sent to me rather than manually do regular check for new emails with the keyword "Pete" in it?
don't need any action from me.
However, emails which require inputs/actions from me usually contains in the first 1-5 lines of it's
message body the following:
a) "Hi Pete" (more than 95% of the cases)
b) "Pete"
c) "Hello Pete"
Q1:
If I press Shift-Ctrl-F to search in the "message header & body", what should I type in as the search
keyword? Is it "Hi Pete" (ie with the double quotes to enclose it) or simply Hi Pete (without double
quotes)?
Q2:
is there any way I can perform a search of Outlook on only the first 5 lines of the message content
to search for the keyword "Pete"?
Q3:
Is there any way to be auto-notified if an email contain the word "Pete" in its message body were
sent to me rather than manually do regular check for new emails with the keyword "Pete" in it?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
https://www.experts-exchange.com/questions/28651308/VBA-Outlook-save-specific-attachments.html
think the above does not quite meet my need. Do guide me with how to install
DIM subroutines etc as I've never used it
think the above does not quite meet my need. Do guide me with how to install
DIM subroutines etc as I've never used it
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Once you have completed the above you'll be actively monitoring your Inbox but there's nothing specified to do so we need to work on that next. Specifically, we need to check each message when it arrives to see if it contains the specified keywords in the first 5 lines of the message body. If so, we'll pop up a message box.
OM Gang
OM Gang
Step3: Parsing routine
Add the following function below the existing code you've already added.
Add the following function below the existing code you've already added.
Public Function Parse2(strSubject As String) As Boolean
On Error GoTo Err_Parse2
Dim blResult As Boolean
Dim lngPos1 As Long, lngPos2 As Long, lngFound As Long
Dim intCount As Integer
Dim strSearch1 As String, strSearch2 As String, strFiveLines As String
'first we'll look for carriage return
strSearch1 = vbCrLf
'we'll look for the following prior to the fifth carriage return
strSearch2 = "Pete"
lngPos1 = 1
intCount = 1
RECURSE:
'find carriage return in string -- search Help (or Google) InStr function
lngPos2 = InStr(lngPos1, strSubject, strSearch1)
If lngPos2 <> 0 Then
'we get here if a carriage return is found so we begin counting the number of carriage returns
'add one to the count
intCount = intCount + 1
'set our new start position to be one more than the found carriage return
lngPos1 = lngPos2 + 1
'we'll only keep looking for carriage returns until we've found 5
If intCount < 6 Then GoTo RECURSE
Else
'we get here if no carriage return found so we'll specify max length as full string length
lngPos2 = Len(strSubject)
End If
'now we search for the keyword but limit scope to the the number of characters in the first 5 lines
strFiveLines = Mid(strSubject, 1, lngPos2)
'search for keyword
lngFound = InStr(strFiveLines, strSearch2)
'if result is not zero then we found it
If lngFound <> 0 Then blResult = True
Exit_Parse2:
Parse2 = blResult
Exit Function
Err_Parse2:
MsgBox Err.Number & " (" & Err.Description & ") in procedure Parse2 of Module Module3"
Resume Exit_Parse2
End Function
Now we just need to tie it all together.
Step4: modify the existing olkFolder_ItemAdd subroutine
Step4: modify the existing olkFolder_ItemAdd subroutine
Private Sub olkFolder_ItemAdd(ByVal Item As Object)
On Error GoTo Err_olkFolder_ItemAdd
Dim blAlert As Boolean
Dim strBody As String, strAlert As String
'we are only going to process messages, e.g. no calendar invites, etc.
If Item.MessageClass = "IPM.Note" Then
'get message body into string variable
strBody = Item.Body
'call parsing routine to see if this message needs attention
blAlert = Parse2(strBody)
'evaluate function return value
If blAlert Then
'message needs to be addressed
strAlert = "Yo Pete! You got a live one" & vbCrLf & vbCrLf & Item.Subject
MsgBox strAlert, vbCritical, "Message Needs Attention"
End If
Exit_olkFolder_ItemAdd:
Exit Sub
Err_olkFolder_ItemAdd:
MsgBox Err.Number & " (" & Err.Description & ") in procedure olkFolder_ItemAdd of VBA Document ThisOutlookSession"
Resume Exit_olkFolder_ItemAdd
End Sub
I tested the parsing routine by passing the following as a sample message body (I added some Debug.Print statements so I could see where the carriage returns were and to make sure the result was accurate.
?Parse2(" 1 " & vbCrLf & " 2 " & vbCrLf & " this is third line" & vbCrLf & " Hi Pate " & vbCrLf & " this is the fifth line of text" & vbCrLf & " and the is the sixth -- Pete ")
5
12
34
50
83
1 <---- first line in message body (including extra spaces)
2 <--- second line in message body (including extra spaces)
this is third line <--- third line
Hi Pate <--- fourth line - intentional mis-spelling of your name
this is the fifth line of text <-- fifth line
False <--- function return value False - Pete was not found
Note that the sixth line isn't processed even though it includes the keyword Pete.
Ran it again with your name spelled correctly
?Parse2(" 1 " & vbCrLf & " 2 " & vbCrLf & " this is third line" & vbCrLf & " Hi Pete " & vbCrLf & " this is the fifth line of text" & vbCrLf & " and the is the sixth -- Pete ")
5
12
34
50
83
1 <---- first line in message body (including extra spaces)
2 <--- second line in message body (including extra spaces)
this is third line <--- third line
Hi Pete <--- fourth line
this is the fifth line of text <-- fifth line
True <--- function return value True - Pete was found
OM Gang
?Parse2(" 1 " & vbCrLf & " 2 " & vbCrLf & " this is third line" & vbCrLf & " Hi Pate " & vbCrLf & " this is the fifth line of text" & vbCrLf & " and the is the sixth -- Pete ")
5
12
34
50
83
1 <---- first line in message body (including extra spaces)
2 <--- second line in message body (including extra spaces)
this is third line <--- third line
Hi Pate <--- fourth line - intentional mis-spelling of your name
this is the fifth line of text <-- fifth line
False <--- function return value False - Pete was not found
Note that the sixth line isn't processed even though it includes the keyword Pete.
Ran it again with your name spelled correctly
?Parse2(" 1 " & vbCrLf & " 2 " & vbCrLf & " this is third line" & vbCrLf & " Hi Pete " & vbCrLf & " this is the fifth line of text" & vbCrLf & " and the is the sixth -- Pete ")
5
12
34
50
83
1 <---- first line in message body (including extra spaces)
2 <--- second line in message body (including extra spaces)
this is third line <--- third line
Hi Pete <--- fourth line
this is the fifth line of text <-- fifth line
True <--- function return value True - Pete was found
OM Gang
ASKER
>Are you not familiar at all with VBA coding and/or working with the VBE (Visual Basic Editor) in Outlook?
Yes, not familiar at all. Don't even know how to get to the orangish "Trust Centre" screen which you posted above
Yes, not familiar at all. Don't even know how to get to the orangish "Trust Centre" screen which you posted above
Now, click the Marco Security ribbon command to get the dialog box I posted above.
If you need help with Step 2 (I posted above) let me know.
OM Gang
If you need help with Step 2 (I posted above) let me know.
OM Gang
ASKER
Gee, thanks very much. I'm just discharged from hospital, not too well yet;
give me till this Tue evening to digest
give me till this Tue evening to digest
@sunhux, hoping you are better soon and sorry to hear you were in hospital. Take your time and let me know if you have questions.
OM Gang
OM Gang
ASKER
Hi OM Gang, got a bit of issue: refer to attached: the Macro Security box is greyed out in
my Outlook though I login using local administrator.
GreyedOutlook-MacroSecurity.jpg
my Outlook though I login using local administrator.
GreyedOutlook-MacroSecurity.jpg
You need to check the 'Developer' option. Doing so will add a Developer tab to your ribbon in Outlook. Then you change your Macro Security settings as in my 5th post above.
OM Gang
OM Gang
ASKER
Thanks very much
The first procedure would check message body, first 5 lines (probably will need to tweak this) for the key words you want.
The second procedure would monitor the Inbox for new messages and call the first procedure passing the message (or just message body?) as a parameter.
OM Gang