• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Using a VBA Custom Form to Send Reoccurring Email Upon Task Completion

Drursion

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
#1
I need to send out a reminder email every other Wednesday, so I thought a simple reoccurring email would do the trick. I then learned that Outlook 2010 does not have such a feature without an add-on. I found and followed this tutorial from Microsoft. I used the following code in a custom task form:

Code:
Sub Item_PropertyChange(ByVal Name)

   Select Case Name

   Case "Status"

           if Item.Status = 2 then '2 = Completed

                   Set NewItem = Application.CreateItem(0)

                   NewItem.To = "change to the email I want to send to@outlook.com; change2@outlook.com"

                   NewItem.Recipients.ResolveAll

                   NewItem.Subject = "This is the message subject text"

                   NewItem.Body = "This is text that will appear in the body of the message."

                   NewItem.Display

                   NewItem.Send

           End IF

   End Select

   End Sub
Then I create a new task with the newly published form and set it to reoccur. The task appears in my Task List. I mark it as complete, but nothing happens. I am a rookie at VBA and have no idea how to fix the code to do what I am looking for. Could someone please assist me in this?

Thanks,

Drursion
 

Drursion

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
#3
Thank you Diane! When I go back to work on Monday I will try this, but I have some questions about the code. Just forgive me because I am trying to understand it some as opposed to just copying and pasting the code.

Code:
Private Sub Application_Reminder(ByVal Item As Object)
  Dim objMsg As MailItem
  Set objMsg = Application.CreateItem(olMailItem)

'IPM.TaskItem to watch for Task Reminders
If Item.MessageClass <> "IPM.Appointment" Then
  Exit Sub
End If

If Item.Categories <> "Send Message" Then
  Exit Sub
End If

  objMsg.To = Item.Location
  objMsg.BCC = "me@slipstick.com"
  objMsg.Subject = Item.Subject
  objMsg.Body = Item.Body
  objMsg.Send

  Set objMsg = Nothing
End Sub
1.) When I create my own category for this do I place the name of that category in Line #10 "Send Message" or Line #6 "IPM.Appointment"?

2.)Why is objMsg.To = Item.Location not shown as a "me@slipstick.com" email to send to or is this just listed and is safe to change to an email?
I would delete the BCC line because I just want to send this to specific people.

3.) My work has set up a global address book that uses # to identify specific groups of people. Is there a way to add one of those groups into the objMsg.To section?

4.) Lastly, What does Set objMsg = Nothing mean and/or do as part of the code?

Thanks,

Drursion
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#4
The new category name goes here, replacing Send Message
If Item.Categories <> "Send Message" Then


2.)Why is objMsg.To = Item.Location not shown as a "me@slipstick.com" email to send to or is this just listed and is safe to change to an email?I would delete the BCC line because I just want to send this to specific people.
The macro the snippet came from uses the fields in an appointment to create the message. if you want to use the macro to send reminders to different people, their alias or address goes in the location field. You can put the addresses there instead.

Add the group alias to it instead:
objMsg.To = "group name"

4.) Lastly, What does Set objMsg = Nothing mean and/or do as part of the code?
It clears the message from memory - although sending the message should do the same thing.