Attachment.SaveAsFile 方法 (Outlook)

将附件保存到指定的路径。

语法

expressionSaveAsFile( _Path_ )

表达 一个代表 Attachment 对象的变量。

参数

名称 必需/可选 数据类型 说明
Path 必需 String 附件保存到的位置。

示例

此 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

另请参阅

附件对象

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。