Using VBA to set Outlook 2007 Out of Office - how do I set the date/time range?

Posted on 2010-01-07
Last Modified: 2012-05-08
I have been using many macros I wrote for various Out of Office messages I leave in Outlook 2007.  We have recently upgraded to Exchange 2007 (finally!!) and now I can't find any info on how to set the Date and Time range and the font & font size settings for Out of Office messages via VBA.  I have attached the code for the macro I use when leaving for the day.
Sub OOO7Home()
    Const PR_OOF_STATE = ""
    Dim olkIS As Outlook.Store
    Dim olkPA As Outlook.PropertyAccessor
    Dim olkOOFMessage As Outlook.StorageItem
    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, "
    EndOfWeek = InputBox("Last day of the week?  y/n", "Out of Office", "n")
    If UCase(EndOfWeek) <> "Y" Then
        Text3 = ".  I will reply to your e-mail in the morning.  If this is an urgent matter, please call 1234."
        Text3 = ".  I will reply to your e-mail Monday morning.  If this is an urgent matter, please call 1234."
    End If

    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
            Exit For
        End If
    Set olkIS = Nothing
    Set olkPA = Nothing
    Set olkOOFMessage = Nothing
End Sub

Open in new window

Question by:pmpatane
    1 Comment
    LVL 28

    Accepted Solution


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    Please help email to staff 2 34
    How to open outlook macro editor w/o running Outlook ? 1 22
    EXCHANGE 2007 4 36
    Calendars woes. 1 18
    My experience with Windows 10 over a one year period and suggestions for smooth operation
    Use email signature images to promote corporate certifications and industry awards.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now