Outlook 2007: Folder.GetStorage method broken
One of the cool new things you can do with the Outlook 2007 Object Model is create and access StorageItem objects. These are hidden messages in .pst or Exchange Mailbox folders that can be a very handy mechanism for storing application settings. The Folder.GetStorage method is used to return (or create if it doesn't exist) a StorageItem object based on the passed parameters (an Entry ID, message class, or subject). However, if you run the code below (which is from the offline Outlook Developer Reference) with anything but a Mail/Post Item folder currently selected in Outlook, the behavior is not what you'd expect:
Sub AssignStorageData()
Dim oInbox As Outlook.Folder
Dim myStorage As Outlook.StorageItem
Set oInbox = Application.ActiveExplorer.CurrentFolder
' Get an existing instance of StorageItem, or create new if it doesn't exist
Set myStorage = oInbox.GetStorage("My Private Storage", olIdentifyBySubject)
' If StorageItem is new, add a custom property for Order Number
If myStorage.Size = 0 Then
myStorage.UserProperties.Add "Order Number", olNumber
End If
' Assign a value to the custom property
myStorage.UserProperties("Order Number").Value = 100
myStorage.Save
End Sub
Now switch to your Inbox. Yup, the "hidden" StorageItem message is not only not created in the non-Mail/Post folder, it is VISIBLE in a completely different folder! It will work as expected if the GetStorage method is called from a Folder object obtained from anything but a Task, Contact, Calendar, Notes or Journal folder - meaning the StorageItem message will be hidden and stored in the specified folder (NOT your Inbox or a completely different folder!).
So I guess we have to wait until Service Pack 1...