Welcome to MSDN Blogs Sign in | Join | Help

Creating an Outlook Appointment based on an Email Message

I've always wanted to do this:  I get an email message and I want to create an appointment from the the message.  It's a simple task and I found that this was one of the goals of Chandler in the book that I'm reading right now, Dreaming in Code by Scott Rosenberg.  Incidentally, I just met Scott at Scoble's Geek/Blogger dinner in San Francisco last week.  From the book, I learned that the software architecture that the Chandler team was using to accomplish this task was very complex.  I looked into the Outlook 2007 UI I did not find this feature.  Last week I visited a customer and the engineering manager there asked how to do this.  The beauty of Outlook is that it is programmable!  In about an hour, I was able to write a short VBA Macro that does the following:

  1. If the current item is an email, create a new appointment item
  2. Copy the categories, body, and subject
  3. Copy the attachments
  4. Add the sender as a meeting participant
  5. Add each email recipient as a meeting participant
  6.      Each To: participant will be a required
  7.      Each CC: or BCC: participant will be optional

I then added the macro to my quick launch bar for an Outlook message and it worked!


I have attached the macro for all of you to try out.

Enjoy,

Michael

5/24/2007: Updated macro to fix bug with copying attachments.

Published Wednesday, May 09, 2007 10:38 AM by Michael S. Scherotter
Filed under:

Attachment(s): NewMeetingRequestFromEmail.bas

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Scheduling your Drive Time in Outlook

When I posted the simple macro to create an appointment from an email message , I got a message from

Friday, May 18, 2007 2:47 AM by Synergist

# re: Creating an Outlook Appointment based on an Email Message

Silly question, but I'm new to macros.  How do I get from the script attachment to the quick launch bar?  Do I need to copy and paste the script to a txt file and drag that to the bar?  Or something else?  Thanks for any help you can offer.

Wednesday, May 23, 2007 6:53 PM by djwriter

# Adding a VBA Macro to Outlook

Silly me. When I posted the macros to create Outlook appointments based on email messages and to schedule

Wednesday, May 23, 2007 11:38 PM by Synergist

# re: Creating an Outlook Appointment based on an Email Message

djwriter,

Here's an explanation of how to add a macro to Outlook:

http://blogs.msdn.com/synergist/archive/2007/05/23/adding-a-vba-macro-to-outlook.aspx

Michael

Wednesday, May 23, 2007 11:43 PM by Michael S. Scherotter

# re: Creating an Outlook Appointment based on an Email Message

This works perfect, great job.

Thursday, May 24, 2007 10:21 AM by Tim Toennies

# re: Creating an Outlook Appointment based on an Email Message

Hello,

I'm new to macros, and I would lik te know if it is possible te rewrite teh script so that i can make a task of certan e-mails.

Micha

Saturday, June 02, 2007 9:57 AM by Micha Schmeink

# re: Creating an Outlook Appointment based on an Email Message

Hello,

Can you help me out ?

I am looking to write a macro that takes

the information of an outlook meeting and creates a word / mail meeting summery

(using the information from the meeting document)

thank you

Jones

Tuesday, June 05, 2007 7:19 PM by jones

# re: Creating an Outlook Appointment based on an Email Message

I'm tryng to modify your script to attach an "email" to the appointment, but with out success

Can you help me?

Thanks

Thursday, June 14, 2007 2:40 PM by MF

# re: Creating an Outlook Appointment based on an Email Message

I've just solved my problem

here is the solution

Set myAttachments = TaskRequest.Attachments

myAttachments.Add app.ActiveInspector.CurrentItem,olEmbeddeditem, 1, email.Subject

Thursday, June 14, 2007 3:32 PM by MF

# re: Creating an Outlook Appointment based on an Email Message

Now that i've moved from outlook 2003 to 2007, my Getting Things Done add-in no longer works. Does anyone know how to create an Outlook task based on an email, which is one of the main things I relied on the add-in for?

Tuesday, June 19, 2007 11:32 PM by Marjorie Wilner

# re: Creating an Outlook Appointment based on an Email Message

Wonderful Macro!!  Been looking for something like this for a couple years and expected O2007 would have it.  Thanks for making me more efficient and expanding my VBA knowledge to Outlook.

Great work!

Tuesday, July 17, 2007 8:12 AM by Michael Karafotis

# re: Creating an Outlook Appointment based on an Email Message

I get an error when this macro runs.

  Run time error '91'

  Object bariable or with block variable not set

the debuger stops at:

  Set item = app.ActiveInspector.CurrentItem

Wednesday, July 25, 2007 12:04 PM by Robert

# re: Creating an Outlook Appointment based on an Email Message

Robert,

1. Are you using Outlook 2007?

2. What is the active inspector?  Is it the Message inspector?

Michael

Wednesday, July 25, 2007 12:22 PM by Michael S. Scherotter

# re: Creating an Outlook Appointment based on an Email Message

Not to make this over-simplified, but you can do the same thing by selected a message or several messages, and dragging them onto the "Calendar" item. This works in pretty much every version of Outlook including 2007.

It won't make the e-mails as attachments, but it does copy the contents into the meeting notice.

Saturday, July 28, 2007 9:52 PM by RCS

# re: Creating an Outlook Appointment based on an Email Message

The macro does the following in addition to the behavior seen by dragging the message to the calendar:

Copy the categories

Copy the attachments

Add the sender as a meeting participant

Add each email recipient as a meeting participant

    Each To: participant will be a required

    Each CC: or BCC: participant will be optional

Sunday, July 29, 2007 8:50 PM by Michael S. Scherotter

# re: Creating an Outlook Appointment based on an Email Message

I think I figured the earlier one out (just shows how much I have been waiting for something like this!). Accomplished it by changing the security settings (Tools->Macro->Secuirty->Programmatic Access).

However, I have another problem.

Since I have numerous filters set up, I normally have my Unread Mail window always open (in fact that is my default, not Inbox). I added your macro to the toolbar here, and tried to invoke it once I saw the message I want displayed in the reading pane. I did not click the message to open in a separate window. I get this error message:

Run-time error '91'; Object variable or With block variable not set. However, if I have the message open in a separate window, I can invoke the Macro either from the Unread Mail window, or from this separate window without any issues.

Is there any fix for this?

thanks!

rgds,

bala

Tuesday, July 31, 2007 9:14 PM by Bala

# re: Creating an Outlook Appointment based on an Email Message

Bala,

I had the same question and fixed it by adding the

GetCurrentItem function listed at:

http://www.outlookcode.com/codedetail.aspx?id=50

and then replacing the Set item line with:

   Set item = GetCurrentItem()

Works now in either the reading pane or when in an e-mail window (depending on which window's macro button is hit).

Saturday, August 04, 2007 5:09 PM by Gary

# re: Creating an Outlook Appointment based on an Email Message

Any way to change this macro so it can run as a rule in Outlook 2K7 and have it use the emails .sendon as the start and end time so a reminder is triggered?

Sunday, August 05, 2007 6:53 AM by Gutharius

# re: Creating an Outlook Appointment based on an Email Message

OK so I fixed my last question. Here is a hacked version of your code that you can use in a rule as a script. I will be using this for all email that I send to myself so I would get calendar reminders for the quick one liner reminder emails I send to myself.

Sub NewMeetingRequestFromEmail(item As Outlook.MailItem)

   Dim email As MailItem

   Set email = item

   Dim meetingRequest As AppointmentItem

   Set meetingRequest = Application.CreateItem(olAppointmentItem)

   meetingRequest.Body = email.Body

   meetingRequest.Subject = email.Subject

   meetingRequest.Start = email.SentOn

   meetingRequest.End = email.SentOn

   meetingRequest.ReminderSet = True

   meetingRequest.ReminderMinutesBeforeStart = 1

   meetingRequest.Save

End Sub

Sunday, August 05, 2007 7:48 AM by Gutharius

# re: Creating an Outlook Appointment based on an Email Message

Gary,

Thanks for that little piece. It worked exactly as I wanted to! I have it in my Unread Mail and Quick Launch bar, so works everywhere.

rgds,

bala

Monday, August 06, 2007 4:23 PM by Bala

# re: Creating an Outlook Appointment based on an Email Message

Thanks mate,

I've been looking for such a snippet code (only the attachment part). I transformed it to work with my own macro for making tasks.

Tuesday, August 21, 2007 3:02 AM by Thijs

# re: Creating an Outlook Appointment based on an Email Message

Hi,

Thanks for this useful technique. One question:

How do I associate an email with an existing task? I would have expected to be able to drag and drop an email onto a task, but that doesn't work. Ideally, one should be able to select an email, click a button or a context-menu item, and select a task to associate the email to, in effect, attaching the email to the existing task.

Wednesday, September 12, 2007 11:41 PM by Aaman

# re: Creating an Outlook Appointment based on an Email Message

Aaman,

In Outlook 2007, I can do this in two ways:

Attaching Item:

1. Open the task for editing

2. Select the Insert tab

3. Press the Attach Item button (in the Include group)

4. Select the item.

Dragging An Item:

1. Open the task for editing

2. Drag the email icon into the body of the task

Thursday, September 13, 2007 12:40 PM by Michael S. Scherotter

# re: Creating an Outlook Appointment based on an Email Message

First, thanks, this gets me most of the way to where i need to go.

I've been playing with this macro to try to see if I can get it to read the simple body to pull out names, dates and a subject to be used in the appointment but I'm not sure if the methods I'm using are correct.

I've been trying to use the .IndexOf and Substring functions to cut up the string and define variables but I seem to have a mismatch with my variables.

Here's the mess I've made, any help?

Dim X As Integer

Dim Y As Integer

Dim name, reason, bodystring As String

bodystring = meetingRequest.Body

X = bodystring.IndexOf("#")

X = X + 2

Y = bodystring.IndexOf("$")

Y = Y - 2

name = bodystring.Substring(X, Y)

X = ""

X = Y + 4

Y = bodystring.IndexOf("!") - 2

meetingRequest.Start = bodystring.Substring(X, Y)

X = ""

X = Y + 4

Y = bodystring.IndexOf("?") - 2

meetingRequest.End = bodystring.Substring(X, Y)

X = ""

X = Y + 4

Y = bodystring.IndexOf("~") - 2

reason = bodystring.Substring(X, Y)

With meetingRequest

       .Subject = "" & name & " - " & reason & ""

       .ReminderSet = False

       .AllDayEvent = True

EndWith

The #, $, !, ? and ~ are just to help me mark and divide up the string.

Been a while since I've tried to do this kind of stuff and I'm not sure if IndexOf and Substring even work with Outlook 2003.

Anyone have any ideas?

Tuesday, October 23, 2007 5:14 PM by Nathan

# re: Creating an Outlook Appointment based on an Email Message

Need to create buttons for:

Permanently delete (without warning pop-up)

Move to (specific folders) with one click action

Macros? I don't know code but I may be able to figure out how to tweak one.

Thanks!!!

Monday, November 05, 2007 1:15 PM by Hugo

# re: Creating an Outlook Appointment based on an Email Message

Michael, I don't know how to "do" macros. but if you answer me I'll find someone who can help me. What I'm trying to do is to have outlook automatically make an appointment if i get a spacific email (these emails can be defined by words in their subject).The date can be found in the body of the email always following a unique name or it can be in the subject. The name of the appointment can be found the same way. the time can be "all day". and the catagory is given to the email through a simple rule I made when i get the email. ok that's about it. can you help? is this possible?

Thank you,

Katie

Tuesday, January 15, 2008 5:35 PM by Gilliankey

# re: Creating an Outlook Appointment based on an Email Message

Mike,

I'm looking for the same thing Katie is.  I have a class that uses an online resource, and this site emails me 24 hours prior to a new assignment deadline.  I'm looking for a rule that can auto-add an appointment without my explicit action.

Can this be done?

Thanks,

Mark

Friday, February 01, 2008 12:39 AM by Snyper912

# re: Creating an Outlook Appointment based on an Email Message

This is a bit crude, but it works for a specific layout of email that I get that has the appt, time and location in, I wanted to add the location to the subject line as well.

Hope it helps

   If LCase(sender.Address) = LCase("mysupplier@theirdomain.com") Then

'      Create meetingRequest

     Dim X As Integer

     Dim Y As Integer

     Dim startDay, startTime, endTime, postcode, bodystring As String

     bodystring = meetingRequest.Body

' get meeting start day and time (line 7) preceded by "Appt Date:"

     X = InStr(bodystring, "Appt Date:")

     X = X + 11

      startDay = Mid(bodystring, X, 10)

     X = X + 14

      startTime = Mid(bodystring, X, 5)

' set meeting end time (add 1 hour to the start time and watch out for 09h/19h)

     Y = Mid(startTime, 2, 1)

     If Y < 9 Then

           Y = Y + 1

           endTime = Mid(startTime, 1, 1) & Y & Mid(startTime, 3)

        Else

           Y = Mid(startTime, 1, 2)

           Y = Y + 1

           endTime = Y & Mid(startTime, 3)

     End If

' get postcode use last bit of 12th line next line is a divider, followed by "Employed:"

' it can vay from 3 characters to 9 characters, and is always preceded by ", "

     X = InStr(bodystring, "Employed:")

     X = X - 75

       postcode = Mid(bodystring, X, 9)

       Y = InStr(postcode, ",")

       If Y > 0 Then

         postcode = Mid(postcode, Y + 1)

       End If

      postcode = UCase(Trim(postcode))

      meetingRequest.Start = startDay & " " & startTime

      meetingRequest.End = startDay & " " & endTime

      meetingRequest.Subject = postcode & " - " & meetingRequest.Subject

      meetingRequest.ReminderSet = False

      meetingRequest.Categories = "Advent"

   End If

Thursday, February 07, 2008 5:52 PM by Gordon Bunker

# re: Creating an Outlook Appointment based on an Email Message

I have been saving a lot of emails into a folder on AOL.  I was wondering if there was a way to write a macro (or script in aol) that would open the email and paste it to the bottom of a word document.  Any help you can provide?

Thanks

N Bill Sheff

Tuesday, February 19, 2008 10:09 PM by N W Sheff

# re: Creating an Outlook Appointment based on an Email Message

I have been saving a lot of emails into a folder on AOL.  I was wondering if there was a way to write a macro (or script in aol) that would open the email and paste it to the bottom of a word document.  Any help you can provide?

Thanks

N Bill Sheff

Tuesday, February 19, 2008 10:09 PM by N W Sheff

# re: Creating an Outlook Appointment based on an Email Message

This keeps making the same appointment for the same mail message for me.  I have Outlook 2003.

Saturday, March 01, 2008 6:47 AM by Help

# re: Creating an Outlook Appointment based on an Email Message

I wrote this macro for Outlook 2007.  I have not tested it for Outlook 2003.

Michael

Saturday, March 01, 2008 12:18 PM by Michael S. Scherotter

# re: Creating an Outlook Appointment based on an Email Message

This is a cool macro, but did you know you can just drag the email to the calendar button, or to a specific date in the calendar in the to-do bar, and it'll create an appointment for you?

Thursday, March 13, 2008 5:26 PM by ChrisRomp

# re: Creating an Outlook Appointment based on an Email Message

Oops -- just saw your response to a similar comment above.  That'll teach me. =)

Thursday, March 13, 2008 5:27 PM by ChrisRomp

# re: Creating an Outlook Appointment based on an Email Message

excelent!! I don't know why outlook 2007 still does not do this?

Monday, March 31, 2008 7:53 AM by miguel

# re: Creating an Outlook Appointment based on an Email Message

Pffft, I can't get it to work, really. Not even a basic calander appointment.

I just want a mail to be copied into a new calander appointment, not even to have all the dates and stuff set, but just simply that the subject is already prefiled and that it has the original e-mail....

Copied the scripts above, they didn't work for me. Tried fixing the code but it doesn't ever work :S

Using Outlook 2007

Wednesday, April 23, 2008 3:57 PM by James

# re: Creating an Outlook Appointment based on an Email Message

Arg, I only know realize this only works when opening the message... *sigh*

How can I get it to work from the preview pane? The adding of the correspondents is really neat tho :)

Wednesday, April 23, 2008 4:03 PM by James

# Updated Outlook Macro for Creating Appointments

Last year I created a simple macro for Microsoft Outlook 2007 that automatically created an appointment

Wednesday, April 23, 2008 8:00 PM by Synergist

# re: Creating an Outlook Appointment based on an Email Message

Thanks!  This is perfect.  I added a flag on mine to categorize e-mails I've made into appointments.

Wednesday, September 03, 2008 9:23 PM by Mike

# Embed current eMail and allow for eMails in Sent Items

I made a couple of changes to the macro:

1) Add the current eMail as an attachment to the appointment rather than copying the body text.

   ' Change this to add the eMail as an attachment to the appointment

   'meetingRequest.Body = email.Body

   meetingRequest.Body = "As referenced in the attached:" & vbCrLf

   meetingRequest.Attachments.Add email, olEmbeddeditem, 1, email.subject

2) Allow for the selected eMail to be one that is in the "Sent Items" folder.

   ' If the selected eMail is in "Sent Items" then the

   ' email.SenderEmailAddress is an empty string

   ' So do not attempt to add it to the meetingRequest as it will fail

   If LCase(email.SenderEmailAddress) <> "" Then

    Set recipient = meetingRequest.Recipients.Add(email.SenderEmailAddress)

    recipient.Resolve

   End If

Thursday, September 25, 2008 12:21 PM by Robert

# re: Creating an Outlook Appointment based on an Email Message

this is cool... but is it possible to save this to a different calendar besides mine. i have another account attached to my email and i want it to save to my second account's calendar which is also shared so everybody can see

thanks

Wednesday, October 08, 2008 1:17 PM by Napoleon

# re: Creating an Outlook Appointment based on an Email Message

Did anyone ever modify this to let you chose a calendar to save the appointment to a different calendar?  

Friday, October 24, 2008 1:08 PM by Brent

# re: Creating an Outlook Appointment based on an Email Message

Love the Macro, but when I use it on an email that has html and graphics, it moves over into the appointment as all text. I am using OL Enterprise 2007.

TIA

Friday, November 07, 2008 11:32 PM by Mr. Ected

# WOW - Many thanks

I wanted this code so much....

Sunday, November 09, 2008 4:27 AM by Nitzan

# re: Creating an Outlook Appointment based on an Email Message

I have been looking for something that links emails to appointments, and appointments to tasks.  This macro has gotten me halfway there. Thank you!  Of course, I must ask, is there something that would get me the rest of the way there?

Tuesday, December 02, 2008 12:27 PM by Michael (Also)

# re: Creating an Outlook Appointment based on an Email Message

I just wanted some basic meeting creating example from VB. For someone just interested in seeing some peoples scheduling availability here is a macro:

Public Sub hbk()

   Dim George As String

   Dim Dick As String

   George = "George W. Bush"

   Dick Cheney = "Dick Cheney"

   Set meeting = Application.CreateItem(olMeeting)

   meeting.Display

   meeting.Recipients.Add (George)

   meeting.Recipients.Add (Dick)

   Set objInsp = meeting.GetInspector

   objInsp.SetCurrentFormPage "Scheduling"

End Sub

Friday, January 09, 2009 12:57 PM by Shawn Michaels

# re: Creating an Outlook Appointment based on an Email Message

Thanks! This is just what I needed. I don't understand why Microsoft doesn't include this function by default.

Monday, April 13, 2009 9:45 AM by charles

# re: Creating an Outlook Appointment based on an Email Message

This is all great and new to me. I need some help creating a macro based on an email received.

On the body of the email, I have the option to accept or decline a project request/order. I would like to create a macro that will allow my outlook to accept each order as it arrives by

1. automatically selecting accept

2. log in to the system using the required username and password

3. complete the acceptance process in the project system

HELP!!!!!!

Thursday, May 07, 2009 1:20 AM by Carolyn

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker