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