Outlook 2007: How to read/write Out-of-Office settings

T

Thomas

For Outlook 2003 the CDO 1.21 was available to manipulate the out-of-office
settings of an Exchange account. How to do this with Outlook 2007?
 
K

Ken Slovak - [MVP - Outlook]

You can still do that with Outlook 2007 using CDO 1.21, you just need to
download CDO from the MS Web site. It's no longer included on the Office CD.

To use the new object model properties in Outlook 2007 you would still look
for a hidden item with a MessageClass of
"IPM.Note.Rules.OofTemplate.Microsoft". To get to the hidden items
collection you would use Folder.GetStorage(), supplying the MessageClass as
the StorageIdentifier argument and
OlStorageIdentifierType.olIdentifyByMessageClass as the
StorageIdentifierType argument.

For any properties you want that aren't exposed to the Outlook object model
you would use the item.PropertyAccessor() object to access those properties.
For that you would use the DASL property tag of the property you want.
 
T

Thomas

Dear Ken,

thank you very much for your response.
I have created the following code snipped from it:

Dim oInbox As Outlook.Folder
Set oInbox = Application.Session.GetDefaultFolder(olFolderInbox)

' Get an instance of the hidden StorageItem
Dim oStorageItem As Outlook.StorageItem
Set oStorageItem =
oInbox.GetStorage("IPM.Note.Rules.OofTemplate.Microsoft",
olIdentifyByMessageClass)

' Manipulate settings
oStorageItem.PropertyAccessor.SetProperty
"http://schemas.microsoft.com/mapi/proptag/0x661D000B", True
oStorageItem.Body = strOutOfOfficeText
oStorageItem.Save

' Cleanup
Set oStorageItem = Nothing
Set oFolder = Nothing

The line containing the call to SetProperty does not work. Probalbly it's
the wrong property tag. Which property tag is the correct one to switch on
the out-of-office reply?

Is oStorageItem.Body the correct place to enter the text of the out-of
-office reply?

Thank you very much!
Thomas
 
K

Ken Slovak - [MVP - Outlook]

What you retrieved from the hidden items of Inbox is the OOF template form.
What you are trying to do is set the OOFState property (PR_OOF_STATE =
0x661D000B) on that form, where it doesn't exist.

That property exists in the mailbox Store object and is set True to set OOF
and False to cancel OOF. Your DASL property tag is absolutely correct,
you're just trying to set it on the wrong object.

BTW, for ease of debugging I'd recommend using an explicit PropertyAccessor
object, as in:

Dim oProp As Outlook.PropertyAccessor
Set oProp = object.PropertyAccessor 'and so on

For what you want the code would run something like this:

Dim oStore As Outlook.Store
Set oStore = Application.Session.DefaultStore
If oStore.ExchangeStoreType = olPrimaryExchangeMailbox Then
' only with default (primary) mailbox
Dim oProp As Outlook.PropertyAccessor
Set oProp = oStore.PropertyAccessor
' set OOFState = true
oProp.SetProperty
"http://schemas.microsoft.com/mapi/proptag/0x661D000B", True
End If

See if that works any better.

To set the OOF message you would use the Body property of the StorageItem
you retrieved for the OOF template.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top