Outlook) (Folder.GetStorage 方法

取得父資料夾上的 StorageItem 物件,以儲存 Outlook 解決方案的資料。

語法

expression。 GetStorage( _StorageIdentifier_ , _StorageIdentifierType_ )

運算式 代表 Folder 物件的變數。

參數

名稱 必要/選用 資料類型 描述
StorageIdentifier 必要 字串 StorageItem 物件的識別碼;根據識別碼類型,其值可能代表項目 ID、郵件類別或主旨。
StorageIdentifierType 必要 OlStorageIdentifierType 會指定 StorageItem 物件之識別碼的類型。

傳回值

用來儲存解決方案資料的 StorageItem 物件。

註解

GetStorage 方法會使用 StorageIdentifier 所指定的識別碼,取得資料夾物件上的 StorageItem,並具有 StorageIdentifierType 所指定的識別碼類型。 StorageItem 是 Folder 中的隱藏項目,會隨著帳戶漫遊,而且在連線和離線時都可使用。

如果您使用 StorageIdentifierType 的 olIdentifyByEntryID 值來指定 StorageItem 的 EntryID,則 GetStorage 方法會傳回具有指定 EntryID 的 StorageItem。 如果使用該 EntryID 無法找到 StorageItem,或是 StorageItem 並不存在,GetStorage 方法便會引發錯誤。

如果您使用 StorageIdentifierType 的 olIdentifyByMessageClass 值來指定 StorageItem 的訊息類別,則 GetStorage 方法會以指定的訊息類別傳回 StorageItem 。 如果有多個項目具有相同的郵件類別,GetStorage 方法便會傳回具有最近 PR_LAST_MODIFICATION_TIME 的項目。 如果存在具有指定之郵件類別的 StorageItem,GetStorage 方法便會以 StorageIdentifier 所指定的郵件類別建立新的 StorageItem。

如果您指定 StorageItem 的主旨,則 GetStorage 方法會傳回 GetStorage 呼叫中指定主旨的 StorageItem。 如果有多個項目具有相同的 Subject,GetStorage 方法則會傳回具有最近 PR_LAST_MODIFICATION_TIME 的項目。 如果指定的主旨不存在 StorageItem,則 GetStorage 方法會使用 StorageIdentifier 指定的主旨建立新的 StorageItem。

如果資料夾的存放區類型不受支援,則 GetStorage 會傳回錯誤。 當呼叫 GetStorage 時,下列存放區會傳回錯誤:

  • Hotmail 存放區

  • 網際網路訊息存取通訊協定 (IMAP) 存放區

  • 委派商店

  • 公用資料夾存放區

新建立的 StorageItem大小為零 (0) ,直到您明確呼叫該項目的 Save 方法為止。

如需為解決方案儲存資料的詳細資訊,請參閱儲存方案的資料。

範例

下列 Visual Basic for Applications 程式碼範例將示範如何使用 StorageItem 物件來儲存私人方案資料。 它會將資料儲存在 [收件匣] 資料夾之 StorageItem 物件的自訂屬性中。 下面將描述這些步驟:

  1. 程式碼範例會呼叫 GetStorage 以取得收件匣中主旨為「我的私人儲存空間」的現有 StorageItem 物件。 如果具有該主旨的 StorageItem 不存在,GetStorage 就會建立具有該主旨的 StorageItem 物件。

  2. 如果 StorageItem 是新建立的,此程式碼範例就會為物件建立自訂屬性 "Order Number"。 請注意,"Order Number" 是 [收件匣] 中隱藏項目的屬性。

  3. 然後程式碼範例會將值指派給 “Order Number”,並儲存 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 支援與意見反應。