Outlook) (ContactItem.SaveAs 方法

將 Microsoft Outlook 專案儲存至指定的路徑,並以指定的檔案類型格式儲存。 如果未指定檔案類型,則會使用 MSG 格式 (.msg)。

語法

運算式SaveAs (路徑類型)

表達 代表 ContactItem 物件的 變數。

參數

名稱 必要/選用 資料類型 描述
Path 必要 字串 要用來儲存項目的路徑。
類型 選用 Variant 要儲存的檔案類型。 可以是下列其中一個 OlSaveAsType 常數: olHTMLolMSGolRTFolTemplateolDocolTXTolVCalolVCardolICalolMSGUnicode

註解

另請注意,即使 olDoc 是有效的 OlSaveAsType 常數,HTML 格式的訊息也無法以檔案格式儲存,而且 olDoc 常數只有在 Microsoft Word 設定為預設電子郵件編輯器時才能運作。

範例

這個 Visual Basic for Applications (VBA) 範例會使用 SaveAs 方法,將目前開啟的專案儲存為 Documents 資料夾中的文字檔,並使用主旨做為檔案名。 若要執行此範例,請確定是否已在使用中視窗內開啟純文字格式的郵件項目。

Sub SaveAsTXT() 
    Dim myItem As Outlook.Inspector 
    Dim objItem As Object 
    Set myItem = myOlApp.ActiveInspector 
    If Not TypeName(myItem) = "Nothing" Then 
        Set objItem = myItem.CurrentItem 
        strname = objItem.Subject 
        'Prompt the user for confirmation 
        Dim strPrompt As String 
        strPrompt = "Are you sure you want to save the item? " & _ 
            "If a file with the same name already exists, " & _ 
            "it will be overwritten with this copy of the file." 
        If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then 
            objItem.SaveAs Environ("HOMEPATH") & "\My Documents\" & strname & ".txt", olTXT 
        End If 
    Else 
        MsgBox "There is no current active inspector." 
    End If 
End Sub

此 Visual Basic for Applications 範例會示範如何使用 SaveAs 方法建立範本。

Sub CreateTemplate() 
    Dim MyItem As Outlook.ContactItem 

    Set MyItem = Application.CreateItem(olContactItem) 
    MyItem.Subject = "Status Report" 
    MyItem.Display 
    MyItem.SaveAs Environ("HOMEPATH") & "\My Documents\statusrep.oft", OlSaveAsType.olTemplate 
End Sub

另請參閱

ContactItem 物件

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應