Marco in search of text in subject line

Status
Not open for further replies.

Jose Campa

Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
I am trying to create a macro that will look in the subject line for the word [Encrypt]. If the word is anywhere in the subject then it just sends the email. But if it is not found, then it will prompt the user to ask them "You are sending an unencrypted message, are you sure you want to send this?". Below is what I have so far but it will prompt the user even though [Encrypt] is or isn't there.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

On Error Resume Next
Dim strSubject As String
strSubject = Msg.Subject

If InStr(Msg.Subject, "[Encrypt]", vbTextCheck) > 0 Then
Prompt$ = "You sending this unencrypted. Are you sure you want to send it?"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Encryption Checker") = vbNo Then
objMsg.Send
Cancel = True
End If
End If

End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
since you do this: strSubject = Msg.Subject
you should do this
If InStr(strSubject, "[Encrypt]", vbTextCheck) > 0 Then

Try this - if it works, add the [] back and see if it still works.
If InStr(lcase(strSubject), "encrypt", vbTextCheck) > 0 Then

you can also add either a msgbox strSubject or debug.print strSubject after that if line to see what it sees as the subject.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
oh, wait - this is saying if encrypt is found in the subject, then ask...
If InStr(Msg.Subject, "[Encrypt]", vbTextCheck) > 0 Then
you want to use = 0, not greater than 0.

also - isn't this sending it if you click no?
Prompt$ = "You sending this unencrypted. Are you sure you want to send it?"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Encryption Checker") = vbNo Then
objMsg.Send
Cancel = True
End If

If you say 'no, don't send' , you are sending it anyway. Remove objmsg.send from there - if you say yes, it will send when the macro ends.
 

Jose Campa

Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
What the code does so far it prompts me "You sending this unencrypted. Are you sure you want to send it?" every time I hit send. Whether I have the word encrypt in the subject line or not. Also note that I am attempting to see if any where in the subject line does it contain the word encrypt. I have tried both avenues and still nothing.

The portion after the prompt is working as I want it. It will send the email even though the word encrypt is not in the subject line if they hit the yes button. This is just a precautionary reminder to the user to encrypt if they need to.
 

Jose Campa

Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
FYI...

When I do the message box it pops up blank.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
FYI...

When I do the message box it pops up blank.
then its not picking up the subject.

oh sheesh, i missed the obvious. the macro identifies the message as item, you use msg - change it to item (or change item to msg)
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

On Error Resume Next
Dim strSubject As String
strSubject = Msg.Subject
 

Jose Campa

Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
then its not picking up the subject.

oh sheesh, i missed the obvious. the macro identifies the message as item, you use msg - change it to item (or change item to msg)
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

On Error Resume Next
Dim strSubject As String
strSubject = Msg.Subject
 

Jose Campa

Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
Okay,

I have it passing the subject line but it still will prompt me even if I have the "encrypt" anywhere in the subject. Since I want it to just contain the keyword should I use Like or Not Like?
then its not picking up the subject.

oh sheesh, i missed the obvious. the macro identifies the message as item, you use msg - change it to item (or change item to msg)
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

On Error Resume Next
Dim strSubject As String
strSubject = Msg.Subject
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This is asking if encrypt is found in any position, ask.
If InStr(Msg.Subject, "[Encrypt]", vbTextCheck) > 0 Then

if you only want it asking when encrypt isn't found try it like this:
If InStr(1, Msg.Subject, "[Encrypt]") = 0 Then
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
M Marco doesn't show up when using Alt-F8 Outlook VBA and Custom Forms 2
D Custom Search Folders not refreshing/updating automatically Using Outlook 0
L New Location for the Search Bar Using Outlook 7
T How can you include Junk Email in Search Results like you can include Deleted Items? Using Outlook 3
J Outlook 2016 After a search in all mailboxes, where is each message that was found? Using Outlook 6
King Mustard Sort search groups by amount of items? Using Outlook 1
V Outlook 2016 will not move emails in search results Using Outlook 4
T Search for incoming e-mails for a specified time range Using Outlook 1
S outlook 2007 calendar search Using Outlook 6
M Outlook macro to automate search and forward process Outlook VBA and Custom Forms 6
J Message search and edit, another way? Outlook VBA and Custom Forms 4
S Create A Search Folder That Looks For Message Class? Outlook VBA and Custom Forms 0
R Outlook for Mac - Advanced Search and Tracking Sent Emails Using Outlook 0
R Search/Jump to a folder by typing its name Outlook VBA and Custom Forms 1
M Sent mail not showing in Sent Items folder; but they can be found with Search Using Outlook 3
A Outlook 2019 having issues with 'people search' and not making suggestions in email To: etc Using Outlook 12
W Search Incomplete Outlook 2016 Using Outlook 5
S Outlook 2007 Calendar instant search problem. Windows 7 Using Outlook 4
S Outlook 2007 Calendar instant search problem. Windows 7 Using Outlook 0
A Using or not using apostrophes in search terms has this changed? Using Outlook 0
R outlook address book search broken Using Outlook 2
K Outlook.com is not showing, or finding via search, all my Contacts (People) Using Outlook 0
W Create Search Folder excluding Specific Email Addresses Using Outlook 5
R What's supposed to appear when just clicking into the search field? Using Outlook 7
A Outlook macro to create search folder with mail categories as criteria Outlook VBA and Custom Forms 3
M possible to search Outlook for multiple email addresses at once? Using Outlook 1
B Instant search with special characters Using Outlook 1
A Search folder refresh Outlook VBA and Custom Forms 3
B Advanced Search in MS Outlook by VBA and SQL Outlook VBA and Custom Forms 2
M email search not working Using Outlook 1
F Search folder for tasks in all task folders Using Outlook 1
W Outlook 2016 search problem persists after applying all known solutions Using Outlook 12
B Looking to filter (or just find/search) for only messages that the sender has sent more than 1 messa Using Outlook 2
B Search: Cannot find which Folder Contains a Message Using Outlook 3
M how to speed up search of shared contacts Using Outlook 0
B When I add more search strings to RULES, it is not processing them Using Outlook 3
C Search with Google Macro? Outlook VBA and Custom Forms 4
E Search for folder by key in subject then move new message to related folder Outlook VBA and Custom Forms 1
E Outlook 2016 Inbox search bug Using Outlook 1
C Filter/Search emails sent to internal Exchange address only Using Outlook 2
M VBA macro for Inbox's attachments search Outlook VBA and Custom Forms 0
P Outlook search is not working at all for Calendar & Tasks Using Outlook 7
M Recent Update Did not Fix Search Problems Using Outlook 7
Commodore Search cannot complete the indexing of your Outlook data Using Outlook 6
M new search just... sucks Using Outlook 4
B Search function in Office 365 has stopped working Using Outlook 3
T Delete Emails from search results Outlook VBA and Custom Forms 1
P Can't search Archive'd Tasks Using Outlook 0
S VBA Code to move mail items from search folder to inbox subfolder Outlook VBA and Custom Forms 4
J Search by catagory Using Outlook 4
Similar threads


















































Top