PDA

View Full Version : Alert list



kastalarial
09-13-2011, 06:40 AM
Need some help.

How do I go by this...

I want to make a code that will prompt outlook to alert me if I am sure to send the message when it sees particular email addresses as subject, cc or bcc?

Something like: "This email will be sent/cc/bcc to john@example.com. Are you sure you want to send?"

Any suggestions will be greatly appreciated.

Thanks!

JP2112
09-13-2011, 11:07 AM
Paste into ThisOutlookSession module and restart Outlook:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim msg As Outlook.mailItem
Dim msgRecips As Outlook.Recipients
Dim msgRecip As Outlook.Recipient
Const emailAddr As String = "john@example.com"
If TypeName(Item) = "MailItem" Then
Set msg = Item
' check msg subject
If InStr(msg.Subject, emailAddr) > 0 Then
If MsgBox("This email will be sent to " & emailAddr & ". Are you sure you want to send?", vbYesNo) = vbNo Then
Cancel = True
Exit Sub
End If
End If
' check B/CC recipients
Set msgRecips = msg.Recipients
For Each msgRecip In msgRecips
If ((msgRecip.Address = emailAddr) And ((msgRecip.Type = olCC) Or (msgRecip.Type = olBCC))) Then
If MsgBox("This email will be sent to " & emailAddr & ". Are you sure you want to send?", vbYesNo) = vbNo Then
Cancel = True
Exit Sub
End If
End If
Next msgRecip
End If
End Sub

kastalarial
09-14-2011, 09:09 AM
I tried placing the code in between

It returned an error
Compile Error: Invalid outside procedure

How do I go by this. Sorry I'm still a noob at this things.

JP2112
09-14-2011, 09:22 AM
See http://www.codeforexcelandoutlook.com/outlook-vba/where-do-i-put-my-outlook-vba-code/ for placement assistance.

Basically, you expand the built-in ThisOutlookSession module and paste the entire code there. Then restart Outlook.

If you already have an ItemSend Event, you have to integrate the procedure into the existing code.

kastalarial
09-14-2011, 09:40 AM
Okay this is what I did. I followed the instructions on the site. But it doesn't seem to do anything. I saved and restarted 3 times. What am I doing wrong?

It works when I save it as a Macro though...

kastalarial
09-14-2011, 09:59 AM
It will really help if you dould do a screen cap of where exactly does it go.

Thanks so much

JP2112
09-14-2011, 11:33 AM
The link that I sent you includes screenshots ... ?

If you've placed the code in the correct place and it still won't run after restarting:

Are macros enabled? Have you digitally signed your VBA project?

Check your security settings to make sure macros can run. Go to Tools > Macro > Security and make sure Medium is selected. I assume Outlook 2003 here, if you use a different version you'll need to search for the exact steps to get to this dialog box.

Restart Outlook after changing the macro security level.

Then use the SELFCERT tool to apply a digital signature to your project (See http://www.howto-outlook.com/howto/selfcert.htm for instruction). Restart Outlook and you should see a warning about macros. Check the "Always trust macros ..." checkbox before clicking "Enable Macros". Again, restart Outlook and the code should work.

Remember this is event code, it will only appear to run when you send an email (not appointment or task) with "john@example.com" in the subject line or with "john@example.com" CC'd or BCC'd.

Also note that any changes made to event code, will require a restart of Outlook in order for the changes to take effect.

What I would do is, after restarting Outlook the second time, go to the VB editor and set a break point at the first line of the code, then send a sample email. The code should execute and immediate go into break mode so you can step through it and watch it work.

kastalarial
09-14-2011, 02:53 PM
Thanks. It worked. It was certs that was wrong. Thank a bunch buddy.

JP2112
09-14-2011, 05:05 PM
You're welcome, FYI what I meant to say was " ... after restarting Outlook the third time ... "