VBA for Dialog Box when sending Email

Outlook version
Outlook 2010 32 bit
Email Account
IMAP
#1
I am looking for help and maybe some VBA that will do the following in Microsoft Outlook 2010:

Prompt me every time that I send an email, asking me if i want to flag this email for follow up

I am tried for days looking for some type of solution and am not getting anywhere. Can someone please help me or point me in the right direction?

All help is much appreciated.
 
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#2
sperrysoftware.com has a follow up addin that might meet your needs, but if you want to got free and cheap, you could use VBA.

This will ask you as the mail hits the sent folder:

Option Explicit

Private WithEvents olSentItems As Items

Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.Session
' instantiate objects declared WithEvents
Set olSentItems = objNS.GetDefaultFolder(olFolderSentMail).Items
Set objNS = Nothing

End Sub

Private Sub olSentItems_ItemAdd(ByVal Item As Object)
On Error Resume Next



Dim prompt As String
prompt$ = "Do you want to flag this message for followup?"
If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbYes Then
With Item
.MarkAsTask olMarkThisWeek

' sets a specific due date
.TaskDueDate = Now + 3
.FlagRequest = "Followup "
.ReminderSet = True
.ReminderTime = Now + 2
.save

End With
End If

End Sub
 
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
#4
Thank you so much for your help, here is my current code but it isn't prompting for the flag, any ideas? Also note I have a current script on top for BCC'ing my gmail address on all sent items, but they shouldn't be affecting each other.

Here is my current code, any help is appreciated:

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

Dim objRecip As Recipient

Dim strMsg As String

Dim res As Integer

Dim strBcc As String

On Error Resume Next

' #### USER OPTIONS ####

' address for Bcc -- must be SMTP address or resolvable

' to a name in the address book

strBcc = "fakeemail@gmail.com"

Set objRecip = Item.Recipients.Add(strBcc)

objRecip.Type = olBCC

If Not objRecip.Resolve Then

strMsg = "Could not resolve the Bcc recipient. " & _

"Do you want still to send the message?"

res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _

"Could Not Resolve Bcc Recipient")

If res = vbNo Then

Cancel = True

End If

End If

Set objRecip = Nothing

End Sub

Private Sub Application_Startup()

Option Explicit

Private WithEvents olSentItems As Items
Dim objNS As NameSpace
Set objNS = Application.Session
' instantiate objects declared WithEvents
Set olSentItems = objNS.GetDefaultFolder(olFolderSentMail).Items
Set objNS = Nothing

End Sub

Private Sub olSentItems_ItemAdd(ByVal Item As Object)
On Error Resume Next
Dim prompt As String
prompt$ = "Do you want to flag this message for followup?"
If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Add flag?") = vbYes Then

With Item
.MarkAsTask olMarkThisWeek
' sets a due date in 7 days
.TaskDueDate = Now + 7
.ReminderSet = True
.ReminderTime = Now + 6
.Save

End With
End If

End Sub
 
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#5
BCC shouldn't affect it - it runs as the message is sent, the itemadd macro runs after its added ot the sent folder.

It's an application startup macro - did you click in the application_startup macro and press run?
 
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#7
I notice you have 2 End Sub in the screenshot- that is not quite the right error message for two end subs, but see if removing one fixes it.
 
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
#8
Here it is again...same result - see the highlighted text is blue? The program is highlighting that when the error comes up so it has something to do with that.

ScreenShot002.jpg
 
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#9
That's the missing sub to the extra end sub. :)

I missed the mixup when i looked at your code earlier and didn't have time to paste it into the VBA editor or i would have picked up on it sooner -

This

Private Sub Application_Startup()
Option Explicit
Private WithEvents olSentItems As Items

<snip>
should be

Option Explicit
Private WithEvents olSentItems As Items

Private Sub Application_Startup()
paste this code at the top of ThisOutlookSession -

Code:
Option Explicit
Private WithEvents olSentItems As Items
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim objRecip As Recipient
Dim strMsg As String
Dim res As Integer
Dim strBcc As String
On Error Resume Next
' #### USER OPTIONS ####
' address for Bcc -- must be SMTP address or resolvable
' to a name in the address book
strBcc = "fakeemail@gmail.com"
Set objRecip = Item.Recipients.Add(strBcc)
objRecip.Type = olBCC
If Not objRecip.Resolve Then
strMsg = "Could not resolve the Bcc recipient. " & _
"Do you want still to send the message?"
res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
"Could Not Resolve Bcc Recipient")
If res = vbNo Then
Cancel = True
End If
End If
Set objRecip = Nothing
End Sub
Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.Session
' instantiate objects declared WithEvents
Set olSentItems = objNS.GetDefaultFolder(olFolderSentMail).Items
Set objNS = Nothing
End Sub
Private Sub olSentItems_ItemAdd(ByVal Item As Object)
On Error Resume Next
Dim prompt As String
prompt$ = "Do you want to flag this message for followup?"
If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Add flag?") = vbYes Then
With Item
.MarkAsTask olMarkThisWeek
' sets a due date in 7 days
.TaskDueDate = Now + 7
.ReminderSet = True
.ReminderTime = Now + 6
.Save
End With
End If
End Sub
 

Similar threads

Top