Email messages .MSG Save as PDF...BUT ALONG WITH THE ATTACHMENTS!

mef1sto

Board Regular
Joined
Oct 31, 2013
Messages
85
Hello!
Recently i've came up this code which is so great but unfortunately the problem with the conversion is that is doesn't save the e-mails attachment as well. It only converts and saves the pdf file after conversion , BUT the attachments of the e-mail are not present in the new .pdf file. Can someone adjust this code so as to convert to .pdf along with the e-mails attachments???
Thank you! Here's the original code:

Rich (BB code):
Sub SaveAsPDFfile()
'====================================================
' Description: Outlook macro to save a selected item in the pdf-format
' Requires Word 2007 SP2 or Word 2010
' Requires a reference to "Microsoft Word <version> Object Library"
' (version is 12.0 or 14.0)
' In VBA Editor; Tools-> References...
'
' author: Robert Sparnaaij
' website: Save e-mail messages as pdf-file | HowTo-Outlook
'====================================================
    'Get all selected items
    Dim MyOlNamespace As Outlook.NameSpace
    Set MyOlNamespace = Application.GetNamespace("MAPI")
    Set MyOlSelection = Application.ActiveExplorer.Selection
    'Make sure at least one item is selected
    If MyOlSelection.Count <> 1 Then
       Response = MsgBox("Please select a single item", vbExclamation, "Save as PDF")
       Exit Sub
    End If
    
    'Retrieve the selected item
    Set MySelectedItem = MyOlSelection.Item(1)
    
    'Get the user's TempFolder to store the item in
    Dim FSO As Object, TmpFolder As Object
    Set FSO = CreateObject("scripting.filesystemobject")
    Set tmpFileName = FSO.GetSpecialFolder(2)
    
    'construct the filename for the temp mht-file
    strName = "www_howto-outlook_com"
    tmpFileName = tmpFileName & "\" & strName & ".mht"
    
    'Save the mht-file
    MySelectedItem.SaveAs tmpFileName, olMHTML
    
    'Create a Word object
    Dim wrdApp As Word.Application
    Dim wrdDoc As Word.Document
    Set wrdApp = CreateObject("Word.Application")
    
    'Open the mht-file in Word without Word visible
    Set wrdDoc = wrdApp.Documents.Open(FileName:=tmpFileName, Visible:=False)
    
    'Define the SafeAs dialog
    Dim dlgSaveAs As FileDialog
    Set dlgSaveAs = wrdApp.FileDialog(msoFileDialogSaveAs)
    
    'Determine the FilterIndex for saving as a pdf-file
    'Get all the filters
    Dim fdfs As FileDialogFilters
    Dim fdf As FileDialogFilter
    Set fdfs = dlgSaveAs.Filters
    'Loop through the Filters and exit when "pdf" is found
    Dim i As Integer
    i = 0
    For Each fdf In fdfs
        i = i + 1
        If InStr(1, fdf.Extensions, "pdf", vbTextCompare) > 0 Then
            Exit For
        End If
    Next fdf
    
    'Set the FilterIndex to pdf-files
    dlgSaveAs.FilterIndex = i
    
    'Get location of My Documents folder
    Dim WshShell As Object
    Dim SpecialPath As String
    Set WshShell = CreateObject("WScript.Shell")
    SpecialPath = WshShell.SpecialFolders("Desktop")
    
    'Construct a safe file name from the message subject
    Dim msgFileName As String
    msgFileName = MySelectedItem.Subject
    Set oRegEx = CreateObject("vbscript.regexp")
    oRegEx.Global = True
    oRegEx.Pattern = "[\\/:*?""<>|]"
    msgFileName = Trim(oRegEx.Replace(msgFileName, ""))
    
    'Set the initial location and file name for SaveAs dialog
    Dim strCurrentFile As String
    dlgSaveAs.InitialFileName = SpecialPath & "\" & msgFileName
       
    'Show the SaveAs dialog and save the message as pdf
    If dlgSaveAs.Show = -1 Then
        strCurrentFile = dlgSaveAs.SelectedItems(1)
        
        'Verify if pdf is selected
        If Right(strCurrentFile, 4) <> ".pdf" Then
            Response = MsgBox("Sorry, only saving in the pdf-format is supported." & _
                vbNewLine & vbNewLine & "Save as pdf instead?", vbInformation + vbOKCancel)
                If Response = vbCancel Then
                    wrdDoc.Close
                    wrdApp.Quit
                    Exit Sub
                ElseIf Response = vbOK Then
                    intPos = InStrRev(strCurrentFile, ".")
                    If intPos > 0 Then
                       strCurrentFile = Left(strCurrentFile, intPos - 1)
                    End If
                    strCurrentFile = strCurrentFile & ".pdf"
                End If
        End If
        
        'Save as pdf
        wrdApp.ActiveDocument.ExportAsFixedFormat OutputFileName:= _
            strCurrentFile, ExportFormat:= _
            wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
            wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=0, To:=0, _
            Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
            CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
            BitmapMissingFonts:=True, UseISO19005_1:=False
    End If
    Set dlgSaveAs = Nothing
    
    ' close the document and Word
    wrdDoc.Close
    wrdApp.Quit
    
    'Cleanup
    Set MyOlNamespace = Nothing
    Set MyOlSelection = Nothing
    Set MySelectedItem = Nothing
    Set wrdDoc = Nothing
    Set wrdApp = Nothing
    Set oRegEx = Nothing
End Sub

Cheers
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Total Mail Converter from Coolutils is a great program intended for converting emails to PDF and other formats. Either you need MSG to PDF or EML to PDF conversions, the program can help you.

Total Mail Converter will help you to convert MSG files to PDF in batches, hundreds of thousands of them at a time. When batch processing, it's crucial to have flexible settings. Total Mail Converter provides everything to get the output PDF files the way you need.

It will give descriptive names to output files and attachments. This way you will always know which attachment refers to which email.

Download the free trial version and convert MSG to PDF for 30 days. Quite enough time to see how it works!
 
Upvote 0
EML file extension support Windows Live Mail, Mozilla Thunderbird and many more other emails client. Here save all email messages for Live mail or other email clients. and the PDF stands for “portable document format”.that is a type of data that save with this extension.


If you want to save your confidential email to pdf format then you have to download EML to PDF utility that converts your EML to PDF. The first step is to install and run the software in your window and the second step is select file /format and the last step is then select output directory then click process now. I am not using but you have to use this utility. I read about this software that is user-friendly and they are providing a trial version


visit here: https://www.osttopstapp.com/eml-to-pdf.html
 
Upvote 0

Forum statistics

Threads
1,223,713
Messages
6,174,041
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top