Solved

Outlook 2003 macro not working in 2007 out of office

Posted on 2009-04-09
3
446 Views
Last Modified: 2012-06-21
I have a series of macros that I use to set different messages in the Out Of Office assistant.  They have worked fine in 2003, but now, the CreateObject("MAPI.Session") is not liked.  I cannot find the 2007 equivalent of this statement.
    Dim Text1, Text2, Text3, TextComma As String
 
    TextComma = ", "
    Text1 = "Thanks for your e-mail! "
    Text2 = "My hours are 7:30 - 4:00 and I am gone for the rest of today, "
    Text3 = ".  I will return your e-mail in the morning. "
 
    Set oSession = CreateObject("MAPI.Session")
    oSession.Logon "", "", False, False
  
    'Set the body text.
    oSession.OutOfOfficeText = Text1 & Chr$(13) & Chr$(13) & Text2 & WeekdayName(Weekday(Date)) & TextComma & Date & Text3
 
    'Turning on Out of Office
    oSession.OutOfOffice = True

Open in new window

0
Comment
Question by:pmpatane
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 250 total points
ID: 24109480
Hi, pmpatane.

Outlook 2007 doesn't use CDO (e.g. MAPI.Session).  Microsoft added the ability to manage properties directly from the Outlook object model without the need for another component (CDO).  Here's a macro that sets the out of office text and turns it on.
Sub OutOfOffice()
    Const PR_OOF_STATE = "http://schemas.microsoft.com/mapi/proptag/0x661D000B"
    Dim olkIS As Outlook.Store, _
        olkPA As Outlook.PropertyAccessor, _
        olkOOFMessage As Outlook.StorageItem
    For Each olkIS In Session.Stores
        If olkIS.ExchangeStoreType = olPrimaryExchangeMailbox Then
            Set olkPA = olkIS.PropertyAccessor
            olkPA.SetProperty PR_OOF_STATE, True
            Set olkOOFMessage = Outlook.Session.GetDefaultFolder(olFolderInbox).GetStorage("IPM.Note.Rules.OofTemplate.Microsoft", olIdentifyByMessageClass)
            olkOOFMessage.Body = Text1 & Chr$(13) & Chr$(13) & Text2 & WeekdayName(Weekday(Date)) & TextComma & Date & Text3
            olkOOFMessage.Save
            Exit For
        End If
    Next
    Set olkIS = Nothing
    Set olkPA = Nothing
    Set olkOOFMessage = Nothing
End Sub

Open in new window

0
 

Author Closing Comment

by:pmpatane
ID: 31568696
That worked flawlessly, but wow, a whole lot more overhead is necessary.  You want to recommend any good books for Outlook 2007 VBA.  My old skills aren't going to be up to snuff.  (Even though my 2003 macros for Send with Read Receipt and adding Voting buttons still work)
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24111305
The best book I know of is "Microsoft Outlook 2007 Programming" by Sue Mosher (ISBN: 978-1-55558-346-0).  She also runs the site http://www.outlookcode.com
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question