MailItem.SaveAs method (Outlook)

Speichert das Microsoft Outlook-Element in dem angegebenen Pfad und in dem Format des angegebenen Dateityps. Wenn kein Dateityp angegeben wurde, wird das MSG-Format (MSG) verwendet.

Syntax

Ausdruck. SaveAs (Pfad, Typ)

Ausdruck Eine Variable, die ein MailItem-Objekt darstellt.

Parameter

Name Erforderlich/Optional Datentyp Beschreibung
Path Erforderlich String Der Pfad, in dem das Element gespeichert werden soll.
Type Optional Variant Der Dateityp zu speichern. Dies kann eine der folgenden OlSaveAsType-Konstanten sein: olHTML, olMSG, olRTF, olTemplate, olDoc, olTXT, olVCal, olVCard, olICal oder olMSGUnicode.

HinwBemerkungeneise

Beachten Sie, dass auch, obwohl OlDoc eine gültige OlSaveAsType -Konstante ist, Nachrichten im HTML-Format nicht im Dokumentformat gespeichert werden und die OlDoc -Konstante funktioniert nur, wenn Microsoft Word als Standard-e-Mail-Editor eingerichtet ist.

Beispiel

Visual Basic für Applikationen (VBA) verwendet die SaveAs -Methode, um die aktuell geöffneten Elements als Textdatei im Ordner Dokumente zu speichern, wobei der Betreff als den Dateinamen. Zum Ausführen dieses Beispiels stellen Sie sicher, dass ein e-Mail-Element im nur-Text-Format in das aktive Fenster geöffnet ist.

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 für Applikationen-Beispiel veranschaulicht das Erstellen einer Vorlage mithilfe der SaveAs -Methode.

Sub CreateTemplate() 
 Dim MyItem As Outlook.MailItem 
 
 Set MyItem = Application.CreateItem(olMailItem) 
 MyItem.Subject = "Status Report" 
 MyItem.To = "Dan Wilson" 
 MyItem.Display 
 MyItem.SaveAs Environ("HOMEPATH") & "\My Documents\statusrep.oft", OlSaveAsType.olTemplate 
End Sub

Siehe auch

MailItem-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.