获取父 Folder 上的 StorageItem 对象,以存储 Outlook 解决方案的数据。
语法
expression。
GetStorage( _StorageIdentifier_ , _StorageIdentifierType_ )
表达式 表示 Folder 对象的变量。
参数
| 名称 | 必需/可选 | 数据类型 | 说明 |
|---|---|---|---|
| StorageIdentifier | 必需 | String | StorageItem 对象; 对象标识符根据标识符类型,该值还可以表示条目 ID、 邮件类或主题。 |
| StorageIdentifierType | 必需 | OlStorageIdentifierType | 指定 邮件 对象标识符的类型。 |
返回值
StorageItem 对象,该对象用于存储解决方案的数据的。
备注
GetStorage 方法使用 StorageIdentifier 指定的标识符获取 Folder 对象上的 StorageItem,并具有 StorageIdentifierType 指定的标识符类型。 邮件 是隐藏的中的项目 文件夹 ,其与该帐户的漫游和联机和脱机时可用。
如果使用 StorageIdentifierType 的 olIdentifyByEntryID 值指定 StorageItem 的 EntryID ,则 GetStorage 方法将返回具有指定 EntryID 的 StorageItem。 如果使用该 EntryID 找不到 StorageItem 或者如果 StorageItem 不存在,则 GetStorage 方法将引发错误。
如果使用 StorageIdentifierType 的 olIdentifyByMessageClass 值为 StorageItem 指定消息类,则 GetStorage 方法将返回具有指定消息类的 StorageItem。 如果有多个项目使用相同的邮件类, GetStorage 方法将返回具有最新 操作 的项。 如果不存在具有指定邮件类的 StorageItem,则 GetStorage 方法将创建一个具有 StorageIdentifier 指定的邮件类的新 StorageItem。
如果您指定了 StorageItem 的使用者,则 GetStorage 方法将返回具有 GetStorage 调用中指定的主题的 StorageItem。 如果有多个具有同一 Subject 的项目,则 GetStorage 方法将返回具有最近 PR_LAST_MODIFICATION_TIME 的项目。 如果不存在具有指定使用者的 StorageItem,则 GetStorage 方法将使用 StorageIdentifier 指定的使用者创建一个新的 StorageItem。
如果不支持该文件夹的存储区类型, GetStorage 会返回一个错误。 下列存储在调用 GetStorage 时返回一个错误:
Hotmail 存储区
Internet 邮件访问协议 (IMAP) 存储区
委托商店
公用文件夹存储区
在显式调用项的 Save 方法之前,新创建的 StorageItem 的大小为 0 (0) 。
有关存储解决方案的数据的详细信息,请参阅存储解决方案的数据。
示例
Visual Basic for Applications 在下面的代码示例演示如何使用 StorageItem 对象存储专用解决方案数据。 它将数据保存在收件箱文件夹中的 邮件 对象的自定义属性。 下面介绍的步骤:
此代码示例调用 GetStorage 来获得现有 StorageItem 对象具有主题"我的专用存储"收件箱中。 如果已存在与该主题没有 邮件 , GetStorage 将创建具有该主题 StorageItem 对象。
如果新创建的 邮件 ,该代码示例创建对象的自定义属性"订单号"。 请注意,"订单号"收件箱中的隐藏项的属性。
然后,代码示例将一个值分配给"订单号",并保存 StorageItem 对象。
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
另请参阅
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。