Share via


Attachment.SaveAsFile-Methode (Outlook)

Speichert die Anlage in dem angegebenen Pfad.

Syntax

Ausdruck. SaveAsFile( _Path_ )

Ausdruck Eine Variable, die ein Attachment-Objekt darstellt.

Parameter

Name Erforderlich/Optional Datentyp Beschreibung
Path Erforderlich String Der Ort, an der die Anlage gespeichert werden soll.

Beispiel

In diesem beispiel für Visual Basic for Applications (VBA) wird die SaveAsFile-Methode verwendet, um die erste Anlage des aktuell geöffneten Elements als Datei im Ordner Dokumente zu speichern, wobei der Anzeigename der Anlage als Dateiname verwendet wird.

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

Siehe auch

Attachment-Objekt

Support und Feedback

Haben Sie Fragen oder Feedback zu Office VBA oder zu dieser Dokumentation? Unter Office VBA-Support und Feedback finden Sie Hilfestellung zu den Möglichkeiten, wie Sie Support erhalten und Feedback abgeben können.