Attachment.SaveAsFile メソッド (Outlook)

添付ファイルを指定されたパスに保存します。

構文

SaveAsFile( _Path_ )

Attachment オブジェクトを表す変数。

パラメーター

名前 必須 / オプション データ型 説明
パス 必須 文字列型 (String) 添付ファイルの保存先のパスを指定します。

このVisual Basic for Applications (VBA) の例では、SaveAsFile メソッドを使用して、現在開いているアイテムの最初の添付ファイルを Documents フォルダー内のファイルとして保存し、添付ファイルの表示名をファイル名として使用します。

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 のサポートおよびフィードバックを参照してください。