將 Microsoft Outlook 項目儲存到指定的路徑並以指定的檔案類型格式。 如果未指定檔案類型,則會使用 MSG 格式 (.msg)。
語法
運算式。另存新檔 (路徑, 輸入)
運算式 代表 PostItem 物件的變數。
參數
| 名稱 | 必要/選用 | 資料類型 | 描述 |
|---|---|---|---|
| Path | 必要 | 字串 | 要用來儲存項目的路徑。 |
| 類型 | 選用 | Variant | 要儲存的檔案類型。 可以是下列其中一個 OlSaveAsType 常數: olHTML、 olMSG、 olRTF、 olTemplate、 olDoc、 olTXT、 olVCal、 olVCard、 olICal 或 olMSGUnicode。 |
註解
另請注意,即使 olDoc 是有效的 OlSaveAsType 常數,HTML 格式的郵件仍無法以文件格式儲存,而且只有在 Microsoft Word 設定為預設電子郵件編輯器時,olDoc 常數才能運作。
範例
此 Visual Basic for Applications (VBA) 範例使用 [另存新檔 ] 方法,使用主旨做為檔案名稱,將目前開啟的項目儲存為 [文件] 資料夾中的文字檔。 若要執行此範例,請確定是否已在使用中視窗內開啟純文字格式的郵件項目。
Sub SaveAsTXT()
Dim myItem As Outlook.Inspector
Dim objItem As Object
Set myItem = Application.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.PostItem
Set MyItem = Application.CreateItem(olPostItem)
MyItem.Subject = "Status Report"
MyItem.Display
MyItem.SaveAs Environ("HOMEPATH") & "\My Documents\statusrep.oft", OlSaveAsType.olTemplate
End Sub
另請參閱
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。