Outlook) (Attachment.SaveAsFile 方法

將附件儲存到指定的路徑中。

語法

expression。 SaveAsFile( _Path_ )

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

參數

名稱 必要/選用 資料類型 描述
Path 必要 字串 儲存附件的位置。

範例

此 Visual Basic for Applications (VBA) 範例使用 SaveAsFile 方法,使用附件的顯示名稱做為檔案名稱,將目前開啟項目的第一個附件儲存為 [文件] 資料夾中的檔案。

Sub SaveAttachment() 
 
 Dim myInspector As Outlook.Inspector 
 
 Dim myItem As Outlook.MailItem 
 
 Dim myAttachments As Outlook.Attachments 
 
 
 
 Set myInspector = Application.ActiveInspector 
 
 If Not TypeName(myInspector) = "Nothing" Then 
 
 If TypeName(myInspector.CurrentItem) = "MailItem" Then 
 
 Set myItem = myInspector.CurrentItem 
 
 Set myAttachments = myItem.Attachments 
 
 'Prompt the user for confirmation 
 
 Dim strPrompt As String 
 
 strPrompt = "Are you sure you want to save the first attachment in the current item to the Documents folder? If a file with the same name already exists in the destination folder, it will be overwritten with this copy of the file." 
 
 If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then 
 
 myAttachments.Item(1).SaveAsFile Environ("HOMEPATH") & "\My Documents\" & _ 
 
 myAttachments.Item(1).DisplayName 
 
 End If 
 
 Else 
 
 MsgBox "The item is of the wrong type." 
 
 End If 
 
 End If 
 
End Sub

另請參閱

Attachment 物件

支援和意見反應

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