Hi all,
I've been working on a macro to check the 'To' field and the 'CC' field for certain email groups, and bring up a dialogue box to warn if certain groups have been detected.
All our email groups are prefixed with an exclamation mark, so the second if block is to check for any message sent to any group, whereas the first block is just for specific groups.
My code is as follows, group names replaced with [name] for privacy.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) Item = MailItem If Item.To = "[name]" Or Item.CC = "[name]" Or Item.To = "[name]" Then Prompt$ = "***WARNING*** This message will be sent to [group name]. Are you sure you wish to send this message?" If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check before Sending") = vbNo Then Cancel = True End If Exit Sub End If If Item.To Like "*!*" Or Item.CC Like "*!*" Then Prompt$ = "WARNING: You are sending this message to an email group with multiple contacts. Are you sure you want to send this message?" If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check before Sending") = vbNo Then Cancel = True End If Exit Sub End If End Sub
No matter what I do, whenever a message is sent whilst the macro is turned on will lose it's Subject line.
If a group affected by the macro is in the To or CC fields, the Subject disappears when the messagebox comes up.
If the To or CC fields contain no restricted group or email, the Subject disappears as the email is being sent.
Turning off the macro stops the problem, so I know the issue lies somewhere in the macro.
Does anyone have any ideas how to resolve this?
I'm happy to use a work-around, if one works! I was thinking along the lines of grabbing the subject line at the start of the code, and appending it right before sending - but this hasn't worked so far in my experiments.