none
Outlook 2010: Wrong Out of office body (by vba) RRS feed

  • Question

  • Hi,

    i try to set up the out of office message by a vba. But the message are changed only in the out of office assitsent, not in the reply message :(

    My Code:

    Const PR_OOF_STATE = "http://schemas.microsoft.com/mapi/proptag/0x661D000B" Dim olkIS As Outlook.Store Dim olkPA As Outlook.PropertyAccessor Dim olkOOFMessage As Outlook.StorageItem Reply = "I'm out of office until" & outDate

    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 = Reply olkOOFMessage.Save Exit For End If Next Set olkIS = Nothing Set olkPA = Nothing Set olkOOFMessage = Nothing

    Can anyone help me? The Variable outDate is changing by my calender. Therefore the out of office message must by dynamic.

    Thank you

    Markus


    Monday, April 16, 2012 2:54 PM

Answers

  • The last one looks correct to me. So GetStorage returns null?

    The following scripot works just fine for me... I run it from "Script" window in OutlookSpy.

    Set olkOOFMessage = Application.Session.GetDefaultFolder(olFolderInbox).GetStorage("IPM.Note.Rules.OofTemplate.Microsoft", olIdentifyByMessageClass)
    MsgBox olkOOFMessage.Body
    

    returns null?

    
    

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Friday, May 4, 2012 6:03 AM
  • Yep. Cached mode can play tricks like that :-)

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Friday, May 4, 2012 6:34 AM
  • Ok now it works.

    1. if you switch off the cache mode, everything works fine

    or

    2. if cache mode is on, you have to wait 1 minute before you close outlook

    Friday, May 4, 2012 6:55 AM

All replies

  • Are you sure you are modifying the right OOF message? There can be more than one OofTemplate message.

    What do you see in OutlookSpy if you click IMAPIFolder and go to the "Associated Contents" tab?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Monday, April 16, 2012 3:04 PM
  • I open the OutlookSpy and there the IMAPIFolder.

    At the Associated Contents Tab i found 2 "IPM.Note.Rules.OofTemplate.Microsoft"

    But now, i don't know what should i do (sorry this is my first Outlook VBA Macro)

    Markus

    Friday, April 20, 2012 6:16 AM
  • According to Microsoft documentation, only lastest will be return if more then one are matching, so simply grab all hidden messages by using GetTable method and iterate through them manually modyfying all that match message class.
    Friday, April 20, 2012 8:18 AM
  • You can have multiple OOF rules that use template messages. Each rules knows which template ity is supposed to use (stored in the PR_RULES_ACTIONS blob).

    If you delete the template messages, Outlook will will recreate them when you open the OOF dialog box.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Friday, April 20, 2012 1:29 PM
  • Did you get any solution for this?

    Saturday, April 21, 2012 12:39 PM
  • Sorry, no.

    I don't know how can i handle that. The Original Code is from my colleague how is not available :(

    Wednesday, April 25, 2012 5:26 AM
  • Did you try deleting both hidden messages to force Outlook to recreate them?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Wednesday, April 25, 2012 4:50 PM
  • I deleted both. Outlook created a new one (only one).

    My script work fine but it didn't change the answer message :(

    Can i find the answer message in the outlook spy?

    Wednesday, May 2, 2012 6:32 AM
  • So can you see the template message in OutlookSpy?

    Can you modify it in OutlookSpy?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Thursday, May 3, 2012 5:16 PM
  • I'm looking for the template message, but i didn't fint that.

    Where can i find it? In OutlookSpy => IMAPIFolder => Associated Contents => IPM.Note.Rules.OofTemplate.Microsoft => ?

    Thanks for your help

    Friday, May 4, 2012 5:19 AM
  • Doesn't your code that calls GetStorage() work for you?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Friday, May 4, 2012 5:25 AM
  • i'm sorry?

    i try in my code

    MsgBox Outlook.Session.GetDefaultFolder(olFolderInbox).GetStorage("IPM.Note.Rules.OofTemplate.Microsoft", olIdentifyByMessageClass)

    but the result is empty, and in Outlookspy i don't know where i can find the message :(

    Friday, May 4, 2012 5:33 AM
  • Are you saying you do not see it in OutlookSpy?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Friday, May 4, 2012 5:35 AM
  • i'm not sure, take a look at the printscreen

    Friday, May 4, 2012 5:42 AM
  • The last one looks correct to me. So GetStorage returns null?

    The following scripot works just fine for me... I run it from "Script" window in OutlookSpy.

    Set olkOOFMessage = Application.Session.GetDefaultFolder(olFolderInbox).GetStorage("IPM.Note.Rules.OofTemplate.Microsoft", olIdentifyByMessageClass)
    MsgBox olkOOFMessage.Body
    

    returns null?

    
    

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Friday, May 4, 2012 6:03 AM
  • Ok, i try your code and i got the correct message by vb, but when i take a look at the gui in outlook (out off office) there is a diffrent message?!
    Friday, May 4, 2012 6:12 AM
  • Now everything works fine :-)

    It needs a round about 30 sec. to change the message in the gui

    I will post the new code here in a few minutes

    Friday, May 4, 2012 6:25 AM
  • Yep. Cached mode can play tricks like that :-)

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Friday, May 4, 2012 6:34 AM
  • Ok now it works.

    1. if you switch off the cache mode, everything works fine

    or

    2. if cache mode is on, you have to wait 1 minute before you close outlook

    Friday, May 4, 2012 6:55 AM