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
 
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.
 
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.
 
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.
 
FYI...

When I do the message box it pops up blank.
 
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
 
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
 
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
 
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.
Similar threads
Thread starter Title Forum Replies Date
M Marco doesn't show up when using Alt-F8 Outlook VBA and Custom Forms 2
efire9207 Addressbook Search Using Outlook 0
Victor_50 Outlook 365 Quick search by period (today, yesterday, last week) completely missing in newest OL 365 Using Outlook 0
A Outlook 2021 needs 'enter' for people search Using Outlook 2
M Search message, then (1) Jump to folder & (2) Select message that you searched for Outlook VBA and Custom Forms 6
G Search Folders and Jump to Folder Outlook VBA and Custom Forms 2
A 'search people' now asks me to 'press enter' Using Outlook 11
A Relocate Search Bar in Outlook Using Outlook 2
A Search folder and move the email Outlook VBA and Custom Forms 0
farrissf Outlook 2016 Optimizing Email Searches in Outlook 2016: Seeking Insights on Quick Search vs Advanced Search Features Using Outlook 0
C Advanced search terms for "Outlook Data File" Using Outlook 1
T How to find or display the sub-folder name for an Archive Search Using Outlook 10
P Search folder: all emails sent to or from a domain Using Outlook 1
T Outlook365 search item listed as "potential matches" can't be opened Using Outlook 0
Victor_50 Outlook 2019 Jump to folder from search folder Outlook VBA and Custom Forms 0
E Outlook 365 Save Selected Email Message as .msg File - oMail.Delete not working when SEARCH Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro GoTo user defined search folder Outlook VBA and Custom Forms 6
J Outlook search bar in Office 2021 Professional Using Outlook 1
T Outlook 365 Search Box reverting to old location Using Outlook 2
P Outlook 2013 search no longer works Using Outlook 2
C How to search for items in Outbox with multiple accounts? Using Outlook 20
J search doesn't find anything Using Outlook 1
kkqq1122 How would I add Search for attachment name Outlook VBA and Custom Forms 3
A Any way to force sort by/group by on search results with VBA? Outlook VBA and Custom Forms 1
B Search and Find Email by Folder Name Outlook VBA and Custom Forms 2
C Search not accurate, but not indexing Using Outlook 9
J How do you disable address search box when typing @ in body of email? Using Outlook 0
H Outlook 2019 intermittent search results Using Outlook 0
D Create advanced search (email) via VBA with LONG QUERY (>1024 char) Outlook VBA and Custom Forms 2
D Advanced e-Mail search on from/to contact group only searches for first 20 contacts in group Using Outlook 0
mll persistently customise columns in outlook advanced search Using Outlook 3
S vba outlook search string with special characters Outlook VBA and Custom Forms 1
S VBA search string with special characters Outlook VBA and Custom Forms 1
H Search Email Header for Content Type Outlook VBA and Custom Forms 1
P Posts in Folder No Longer Group by Conversation Column After Search Using Outlook 0
O Advanced search - can I use booleans Using Outlook 3
Y Filter unread emails in a search folder vba help Outlook VBA and Custom Forms 0
M Reverting The Outlook Search Box Location (or other undesired additions) Using Outlook 1
M Something went wrong and your search couldn't be completed Using Outlook 1
M Disable Contact Card Results when using "Search People" in Outlook Ribbon Using Outlook 7
J outlook 2007 doesn't let me choose which .pst to search Using Outlook 2
P outlook 2008 search box criteria couldn't be saved Using Outlook 2
C Outlook with Office365 - search across account, by date rate, in multiple folders - how? Using Outlook 2
D Custom Search Folders not refreshing/updating automatically Using Outlook 0
L New Location for the Search Bar Using Outlook 6
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

Similar threads

Back
Top