Sub AssignStorageData()
Dim oInbox As Outlook.Folder
Dim myStorage As Outlook.StorageItem
Set oInbox = Application.Session.GetDefaultFolder(olFolderInbox)
' 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
Sub getXlListStorageItem()
Dim oInbox As Outlook.Folder
Dim criteria
Dim oTable
Dim i, oRow
Set oInbox = Application.Session.GetDefaultFolder(olFolderInbox)
criteria = "[MessageClass]='IPM.Storage'"
Set oTable = oInbox.GetTable(criteria, olHiddenItems)
MsgBox oTable.GetRowCount
Dim appExcel As Excel.Application
Set appExcel = CreateObject("Excel.application")
appExcel.Visible = True
appExcel.Workbooks.add
i = 2
'Enumerate the table using test for EndOfTable
Do Until (oTable.EndOfTable)
Set oRow = oTable.GetNextRow()
appExcel.Cells(i, 1).Value = (oRow("Subject"))
appExcel.Cells(i, 2).Value = (oRow("Subject"))
appExcel.Cells(i, 3).Value = (oRow("MessageClass"))
appExcel.Cells(i, 4).Value = (oRow("CreationTime"))
appExcel.Cells(i, 5).Value = (oRow("LastModificationTime"))
i = i + 1
Loop
End Sub
Sub test_getStorageItem()
Dim myStorageItem As Outlook.StorageItem
Set myStorageItem = getStorageItem("My Private Storage")
MsgBox myStorageItem.Subject & vbCr & "attachments = " & myStorageItem.Attachments.Count _
& vbCr & "Order Number=" & myStorageItem.UserProperties("Order Number")
Set myStorageItem = Nothing
End Sub
Function getStorageItem(Subject) As Outlook.StorageItem
Dim oInbox As Outlook.Folder
Dim oTable As Outlook.Table
Dim oRow
Dim criteria
Set oInbox = Application.Session.GetDefaultFolder(olFolderInbox)
criteria = "[MessageClass]='IPM.Storage'"
Set oTable = oInbox.GetTable(criteria, olHiddenItems)
'Enumerate the table using test for EndOfTable
Do Until (oTable.EndOfTable)
Set oRow = oTable.GetNextRow()
If oRow("Subject") = Subject Then
Set getStorageItem = Application.Session.GetItemFromID(oRow("EntryID"))
Exit Do
End If
Loop
Set oInbox = Nothing
Set oTable = Nothing
Set oRow = Nothing
End Function