KutoolsforOffice — Eine Lösung, fünf leistungsstarke Tools.Mehr erreichen mit weniger Aufwand.März-Aktion: 20 % Rabatt

Wie konvertiert oder speichert man eine E-Mail mitsamt ihren Anhängen in einer einzigen PDF-Datei in Outlook?

AutorSiluvia Änderungsdatum

Dieser Artikel erklärt, wie Sie eine E-Mail-Nachricht mitsamt allen enthaltenen Anhängen in einer einzigen PDF-Datei in Outlook speichern.

Konvertieren oder Speichern einer E-Mail und ihrer Anhänge in einer einzigen PDF-Dateien mithilfe von VBA-Code


Konvertieren oder Speichern einer E-Mail und ihrer Anhänge in einer einzigen PDF-Dateien mithilfe von VBA-Code

So speichern Sie eine E-Mail mitsamt allen Anhängen als eine einzige PDF-Datei in Outlook:

1. Wählen Sie eine E-Mail mit Anhängen aus, die Sie in einer einzigen PDF-Datei speichern möchten, und drücken Sie anschließend die Alt+F11-Tasten, um das Microsoft Visual Basic for Applications-Fenster zu öffnen.

2. Klicken Sie im Microsoft Visual Basic for Applications-Fenster auf Einfügen > Modul. Kopieren Sie anschließend den unten stehenden VBA-Code in das Modulfenster.

VBA-Code: E-Mail und Anhänge in einer einzigen PDF-Dateien speichern

Public Sub MergeMailAndAttachsToPDF()
'Update by Extendoffice 2018/3/5
Dim xSelMails As MailItem
Dim xFSysObj As FileSystemObject
Dim xOverwriteBln As Boolean
Dim xLooper As Integer
Dim xEntryID As String
Dim xNameSpace As Outlook.NameSpace
Dim xMail As Outlook.MailItem
Dim xExt As String
Dim xSendEmailAddr, xCompanyDomain As String
Dim xWdApp As Word.Application
Dim xDoc, xNewDoc As Word.Document
Dim I As Integer
Dim xPDFSavePath As String
Dim xPath As String
Dim xFileArr() As String
Dim xExcel As Excel.Application
Dim xWb As Workbook
Dim xWs As Worksheet
Dim xTempDoc As Word.Document

On Error Resume Next
If (Outlook.ActiveExplorer.Selection.Count > 1) Or (Outlook.ActiveExplorer.Selection.Count = 0) Then
    MsgBox "Please Select a email.", vbInformation + vbOKOnly
    Exit Sub
End If
Set xSelMails = Outlook.ActiveExplorer.Selection.Item(1)
xEntryID = xSelMails.EntryID
Set xNameSpace = Application.GetNamespace("MAPI")
Set xMail = xNameSpace.GetItemFromID(xEntryID)

xSendEmailAddr = xMail.SenderEmailAddress
xCompanyDomain = Right(xSendEmailAddr, Len(xSendEmailAddr) - InStr(xSendEmailAddr, "@"))
xOverwriteBln = False
Set xExcel = New Excel.Application
xExcel.Visible = False
Set xWdApp = New Word.Application
xExcel.DisplayAlerts = False
xPDFSavePath = xExcel.Application.GetSaveAsFilename(InitialFileName:="", FileFilter:="PDF Files(*.pdf),*.pdf")
If xPDFSavePath = "False" Then
    xExcel.DisplayAlerts = True
    xExcel.Quit
    xWdApp.Quit
    Exit Sub
End If
xPath = Left(xPDFSavePath, InStrRev(xPDFSavePath, "\"))
cPath = xPath & xCompanyDomain & "\"
yPath = cPath & Format(Now(), "yyyy") & "\"
mPath = yPath & Format(Now(), "MMMM") & "\"
If Dir(xPath, vbDirectory) = vbNullString Then
   MkDir xPath
End If
EmailSubject = CleanFileName(xMail.Subject)
xSaveName = Format(xMail.ReceivedTime, "yyyymmdd") & "_" & EmailSubject & ".doc"
Set xFSysObj = CreateObject("Scripting.FileSystemObject")
If xOverwriteBln = False Then
   xLooper = 0
  Do While xFSysObj.FileExists(yPath & xSaveName)
      xLooper = xLooper + 1
      xSaveName = Format(xMail.ReceivedTime, "yyyymmdd") & "_" & EmailSubject & "_" & xLooper & ".doc"
   Loop
Else
   If xFSysObj.FileExists(yPath & xSaveName) Then
      xFSysObj.DeleteFile yPath & xSaveName
   End If
End If
xMail.SaveAs xPath & xSaveName, olDoc
If xMail.Attachments.Count > 0 Then
   For Each atmt In xMail.Attachments
      xExt = SplitPath(atmt.filename, 2)
      If (xExt = ".docx") Or (xExt = ".doc") Or (xExt = ".docm") Or (xExt = ".dot") Or (xExt = ".dotm") Or (xExt = ".dotx") _
      Or (xExt = ".xlsx") Or (xExt = ".xls") Or (xExt = ".xlsm") Or (xExt = ".xlt") Or (xExt = ".xltm") Or (xExt = ".xltx") Then
        atmtName = CleanFileName(atmt.filename)
        atmtSave = xPath & Format(xMail.ReceivedTime, "yyyymmdd") & "_" & atmtName
        atmt.SaveAsFile atmtSave
      End If
   Next
End If
Set xNewDoc = xWdApp.Documents.Add("Normal", False, wdNewBlankDocument, False)
Set xFilesFld = xFSysObj.GetFolder(xPath)
xFileArr() = GetFiles(xPath)
For I = 0 To UBound(xFileArr()) - 1
    xExt = SplitPath(xFileArr(I), 2)
    If (xExt = ".xlsx") Or (xExt = ".xls") Or (xExt = ".xlsm") Or (xExt = ".xlt") Or _
       (xExt = ".xltm") Or (xExt = ".xltx") Then  'conver excel to word
        Set xWb = xExcel.Workbooks.Open(xPath & xFileArr(I))
        Set xTempDoc = xWdApp.Documents.Add("Normal", False, wdNewBlankDocument, False)
        Set xWs = xWb.ActiveSheet
        xWs.UsedRange.Copy
        xTempDoc.Content.PasteAndFormat wdFormatOriginalFormatting
        xTempDoc.SaveAs2 xPath & xWs.Name + ".docx", wdFormatXMLDocument
        xWb.Close False
        Kill xPath & xFileArr(I)
        xTempDoc.Close wdDoNotSaveChanges, wdOriginalDocumentFormat, False
    End If
Next
xExcel.DisplayAlerts = True
xExcel.Quit
xFileArr() = GetFiles(xPath)
'Merge Documents
For I = 0 To UBound(xFileArr()) - 1
    xExt = SplitPath(xFileArr(I), 2)
    If (xExt = ".docx") Or (xExt = ".doc") Or (xExt = ".docm") Or (xExt = ".dot") Or _
       (xExt = ".dotm") Or (xExt = ".dotx") Then
        MergeDoc xWdApp, xPath & xFileArr(I), xNewDoc
        Kill xPath & xFileArr(I)
    End If
Next
xNewDoc.Sections.Item(1).Range.Delete wdCharacter, 1
xNewDoc.SaveAs2 xPDFSavePath, wdFormatPDF
xNewDoc.Close wdDoNotSaveChanges, wdOriginalDocumentFormat, False
xWdApp.Quit
Set xMail = Nothing
Set xNameSpace = Nothing
Set xFSysObj = Nothing
MsgBox "Merged successfully", vbInformation + vbOKOnly
End Sub

Public Function SplitPath(FullPath As String, ResultFlag As Integer) As String
Dim SplitPos As Integer, DotPos As Integer
SplitPos = InStrRev(FullPath, "/")
DotPos = InStrRev(FullPath, ".")
Select Case ResultFlag
Case 0
   SplitPath = Left(FullPath, SplitPos - 1)
Case 1
   If DotPos = 0 Then DotPos = Len(FullPath) + 1
   SplitPath = Mid(FullPath, SplitPos + 1, DotPos - SplitPos - 1)
Case 2
   If DotPos = 0 Then DotPos = Len(FullPath)
   SplitPath = Mid(FullPath, DotPos)
Case Else
   Err.Raise vbObjectError + 1, "SplitPath Function", "Invalid Parameter!"
End Select
End Function
  
Function CleanFileName(StrText As String) As String
Dim xStripChars As String
Dim xLen As Integer
Dim I As Integer
xStripChars = "/\[]:=," & Chr(34)
xLen = Len(xStripChars)
StrText = Trim(StrText)
For I = 1 To xLen
StrText = Replace(StrText, Mid(xStripChars, I, 1), "")
Next
CleanFileName = StrText
End Function

Function GetFiles(xFldPath As String) As String()
On Error Resume Next
Dim xFile As String
Dim xFileArr() As String
Dim xArr() As String
Dim I, x As Integer
x = 0
ReDim xFileArr(1)
xFileArr(1) = xFldPath '& "\"
xFile = Dir(xFileArr(1) & "*.*")
Do Until xFile = ""
    x = x + 1
    xFile = Dir
Loop
ReDim xArr(0 To x)
x = 0
xFile = Dir(xFileArr(1) & "*.*")
Do Until xFile = ""
    xArr(x) = xFile
    x = x + 1
    xFile = Dir
Loop
GetFiles = xArr()
End Function

Sub MergeDoc(WdApp As Word.Application, xFileName As String, Doc As Document)
Dim xNewDoc As Document
Dim xSec As Section
    Set xNewDoc = WdApp.Documents.Open(filename:=xFileName, Visible:=False)
    Set xSec = Doc.Sections.Add
    xNewDoc.Content.Copy
    xSec.PageSetup = xNewDoc.PageSetup
    xSec.Range.PasteAndFormat wdFormatOriginalFormatting
    xNewDoc.Close
End Sub

3. Klicken Sie auf Extras > Verweise, um das Verweise-Dialogfeld zu öffnen. Aktivieren Sie die Kontrollkästchen für Microsoft Excel Object Library, Microsoft Scripting Runtime und Microsoft Word Object Library, und klicken Sie anschließend auf die OK-Schaltfläche. Siehe Screenshot:

Schritt 1 zum Speichern von E-Mail-Anhängen als einzelne PDF

4. Drücken Sie die F5-Taste oder klicken Sie auf die Ausführen-Schaltfläche, um den Code auszuführen. Anschließend öffnet sich das Speichern unter-Dialogfeld. Wählen Sie einen Ordner zum Speichern der Datei aus, vergeben Sie einen Namen für die PDF-Datei und klicken Sie auf die Speichern-Schaltfläche. Siehe Screenshot:

Schritt 2 zum Speichern von E-Mail-Anhängen als einzelne PDF

5. Anschließend wird ein Microsoft Outlook-Dialogfeld geöffnet. Klicken Sie bitte auf die OK-Schaltfläche.

Schritt 3 zum Speichern von E-Mail-Anhängen als einzelne PDF

Die ausgewählte E-Mail samt allen Anhängen wurde nun in einer einzigen PDF-Datei gespeichert.

Hinweis: Dieses VBA-Skript funktioniert ausschließlich mit Anhängen aus Microsoft Word und Excel.


Speichern Sie ausgewählte E-Mails in Outlook problemlos als Dateien unterschiedlicher Formate:

Mithilfe des Bulk Save-Tools von Kutools für Outlookkönnen Sie mehrere ausgewählte E-Mails problemlos als einzelne HTML-Format-Datei, TXT-Format-Datei, Word-Dokument, CSV-Datei sowie PDF-Dateien in Outlook speichern, wie im folgenden Screenshot gezeigt.Laden Sie jetzt die kostenlose Version von Kutools für Outlook herunter!

Schritt 1 zum Speichern von E-Mail-Anhängen als einzelne PDF

Verwandte Artikel:


Beste Office-Produktivitätswerkzeuge

Erleben Sie das komplett neue Kutools für Outlook mit 100+ unglaublichen Funktionen!Jetzt zum Download klicken!

🤖KUTOOLS AI:Nutzt fortschrittliche KI-Technologie, um E-Mails mühelos zu verwalten – einschließlich Beantworten, Zusammenfassen, Optimieren, Erweitern, Übersetzen und Verfassen von E-Mails.

📧E-Mail-Automatisierung: Automatische Antworten (verfügbar für POP und IMAP) / E-Mails zeitgesteuert versenden / Beim Senden automatisch CC/BCC basierend auf Regeln hinzufügen / Automatische Weiterleitung (Erweiterte Regeln) / Automatische Grußformel einfügen / Mehrfachadressierte E-Mails automatisch in Einzelnachrichten aufteilen

📨E-Mail-Verwaltung: E-Mails zurückrufen, Betrugs-E-Mails anhand von Betreffzeilen und weiteren Kriterien blockieren, doppelte E-Mails löschen, Erweiterte Suche, Ordner organisieren

📁Anhänge Pro: Stapelweise speichern / Stapelweise lösen / Stapelweise komprimieren / Automatisch speichern / Automatisch abtrennen / Automatische Komprimierung

🌟Oberflächenzauber:😊Noch mehr hübsche und coole Emojis/Benachrichtigung bei wichtigen eingehenden E-Mails/Outlook minimieren statt schließen...

👍Ein-Klick-Wunder: Allen mit Anhängen antworten / Anti-Phishing-E-Mails / 🕘Aktuelle Uhrzeit der Absender-Zeitzone anzeigen...

👩🏼‍🤝‍👩🏻Kontakte & Kalender:Stapelweise Kontakte aus ausgewählten E-Mails hinzufügen/Eine Kontaktgruppe in einzelne Kontakte aufteilen/Geburtstagserinnerung entfernen...

Nutzen Sie Kutools in Ihrer bevorzugten Sprache – mit Unterstützung für Englisch, Spanisch, Deutsch, Französisch, Chinesisch und über 40 weitere Sprachen!

Kutools für Outlook mit nur einem Klick sofort freischalten! Warten Sie nicht – laden Sie jetzt herunter und steigern Sie Ihre Effizienz!

kutools for outlook features1kutools for outlook features2

🚀 Ein-Klick-Download – Holen Sie sich alle Office-Add-Ins

Stark empfohlen: Kutools for Office (5-in-1)

Mit einem Klick fünf Installationsprogrammegleichzeitig herunterladen –Kutools für Excel, Outlook, Word, PowerPointund Office Tab Pro.Jetzt zum Download klicken!

  • Ein-Klick-Komfort: Laden Sie alle fünf Installationspakete mit nur einem Klick herunter.
  • 🚀Bereit für jede Office-Aufgabe: Installieren Sie die Add-Ins, die Sie brauchen – genau dann, wenn Sie sie benötigen.
  • 🧰Enthalten: Kutools für Excel / Kutools für Outlook / Kutools für Word / Office Tab Pro / Kutools for PowerPoint