Automatically Convert Email Attachment to Pdf and Upload to Website

How to convert or salvage electronic mail and attachments to a single PDF file in Outlook?

This article is talking nearly saving an e-mail bulletin and all attachments within information technology to a unmarried PDF file in Outlook.

Convert or save e-mail and attachments to a single PDF file with VBA lawmaking


Convert or save e-mail and attachments to a unmarried PDF file with VBA lawmaking

Please do as follows to save email with its all attachments to a unmarried PDF file in Outlook.

i. Select an email with attachments you will salve to a single PDF file, and then printing the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.

2. In the Microsoft Visual Basic for Applications window, click Insert > Module. And then copy the below VBA code into the Module window.

VBA code: Save electronic mail and zipper to a unmarried PDF file

            Public Sub MergeMailAndAttachsToPDF() 'Update by Extendoffice 2018/three/5 Dim xSelMails As MailItem Dim xFSysObj Every bit FileSystemObject Dim xOverwriteBln Every bit Boolean Dim xLooper As Integer Dim xEntryID As String Dim xNameSpace Every bit Outlook.NameSpace Dim xMail Equally Outlook.MailItem Dim xExt As String Dim xSendEmailAddr, xCompanyDomain As String Dim xWdApp As Discussion.Awarding Dim xDoc, xNewDoc As Word.Document Dim I As Integer Dim xPDFSavePath Every bit String Dim xPath As Cord Dim xFileArr() Equally String Dim xExcel Every bit Excel.Application Dim xWb As Workbook Dim xWs As Worksheet Dim xTempDoc As Discussion.Certificate  On Mistake Resume Next If (Outlook.ActiveExplorer.Choice.Count > 1) Or (Outlook.ActiveExplorer.Selection.Count = 0) And so     MsgBox "Please Select a email.", vbInformation + vbOKOnly     Exit Sub End If Set xSelMails = Outlook.ActiveExplorer.Selection.Item(1) xEntryID = xSelMails.EntryID Fix 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.Awarding xExcel.Visible = False Set xWdApp = New Word.Application xExcel.DisplayAlerts = Fake xPDFSavePath = xExcel.Awarding.GetSaveAsFilename(InitialFileName:="", FileFilter:="PDF Files(*.pdf),*.pdf") If xPDFSavePath = "False" And so     xExcel.DisplayAlerts = True     xExcel.Quit     xWdApp.Quit     Leave Sub End If xPath = Left(xPDFSavePath, InStrRev(xPDFSavePath, "\")) cPath = xPath & xCompanyDomain & "\" yPath = cPath & Format(At present(), "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 & ".doctor"    Loop Else    If xFSysObj.FileExists(yPath & xSaveName) Then       xFSysObj.DeleteFile yPath & xSaveName    Terminate If End If xMail.SaveAs xPath & xSaveName, olDoc If xMail.Attachments.Count > 0 So    For Each atmt In xMail.Attachments       xExt = SplitPath(atmt.filename, 2)       If (xExt = ".docx") Or (xExt = ".dr.") 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 together("Normal", Fake, wdNewBlankDocument, Fake) Set xFilesFld = xFSysObj.GetFolder(xPath) xFileArr() = GetFiles(xPath) For I = 0 To UBound(xFileArr()) - i     xExt = SplitPath(xFileArr(I), 2)     If (xExt = ".xlsx") Or (xExt = ".xls") Or (xExt = ".xlsm") Or (xExt = ".xlt") Or _        (xExt = ".xltm") Or (xExt = ".xltx") And then  'conver excel to give-and-take         Set xWb = xExcel.Workbooks.Open(xPath & xFileArr(I))         Prepare xTempDoc = xWdApp.Documents.Add("Normal", False, wdNewBlankDocument, False)         Set up xWs = xWb.ActiveSheet         xWs.UsedRange.Re-create         xTempDoc.Content.PasteAndFormat wdFormatOriginalFormatting         xTempDoc.SaveAs2 xPath & xWs.Name + ".docx", wdFormatXMLDocument         xWb.Close Fake         Kill xPath & xFileArr(I)         xTempDoc.Close wdDoNotSaveChanges, wdOriginalDocumentFormat, False     End If Adjacent xExcel.DisplayAlerts = True xExcel.Quit xFileArr() = GetFiles(xPath) 'Merge Documents For I = 0 To UBound(xFileArr()) - ane     xExt = SplitPath(xFileArr(I), 2)     If (xExt = ".docx") Or (xExt = ".physician") 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, i xNewDoc.SaveAs2 xPDFSavePath, wdFormatPDF xNewDoc.Close wdDoNotSaveChanges, wdOriginalDocumentFormat, False xWdApp.Quit Prepare xMail = Nothing Gear up xNameSpace = Nothing Gear up xFSysObj = Zilch MsgBox "Merged successfully", vbInformation + vbOKOnly End Sub  Public Office SplitPath(FullPath As String, ResultFlag Equally Integer) As String Dim SplitPos As Integer, DotPos Equally Integer SplitPos = InStrRev(FullPath, "/") DotPos = InStrRev(FullPath, ".") Select Case ResultFlag Case 0    SplitPath = Left(FullPath, SplitPos - ane) Instance i    If DotPos = 0 And then DotPos = Len(FullPath) + 1    SplitPath = Mid(FullPath, SplitPos + 1, DotPos - SplitPos - 1) Example 2    If DotPos = 0 Then DotPos = Len(FullPath)    SplitPath = Mid(FullPath, DotPos) Example Else    Err.Enhance vbObjectError + 1, "SplitPath Function", "Invalid Parameter!" End Select End Office    Function CleanFileName(StrText As String) Equally String Dim xStripChars Every bit String Dim xLen Equally Integer Dim I As Integer xStripChars = "/\[]:=," & Chr(34) xLen = Len(xStripChars) StrText = Trim(StrText) For I = 1 To xLen StrText = Supersede(StrText, Mid(xStripChars, I, 1), "") Next CleanFileName = StrText End Function  Office GetFiles(xFldPath As String) As String() On Mistake Resume Next Dim xFile As Cord Dim xFileArr() As String Dim xArr() As String Dim I, x As Integer x = 0 ReDim xFileArr(1) xFileArr(one) = xFldPath '& "\" xFile = Dir(xFileArr(1) & "*.*") Do Until xFile = ""     ten = x + 1     xFile = Dir Loop ReDim xArr(0 To x) x = 0 xFile = Dir(xFileArr(1) & "*.*") Do Until xFile = ""     xArr(ten) = xFile     x = x + ane     xFile = Dir Loop GetFiles = xArr() End Function  Sub MergeDoc(WdApp Every bit Word.Application, xFileName As Cord, Physician Equally Document) Dim xNewDoc As Document Dim xSec As Department     Set xNewDoc = WdApp.Documents.Open(filename:=xFileName, Visible:=False)     Set xSec = Dr..Sections.Add together     xNewDoc.Content.Copy     xSec.PageSetup = xNewDoc.PageSetup     xSec.Range.PasteAndFormat wdFormatOriginalFormatting     xNewDoc.Close End Sub          

iii. Click Tools > References to open the References dialog box. Bank check the Microsoft Excel Object Library, Microsoft Scripting Runtime and Microsoft Word Object Library boxes and then click the OK button. Meet screenshot:

four. Printing the F5 primal or click the Run button to run the code. Then a Salve Equally dialog box pops upwards, please specify a folder to salvage the file, and then give the PDF file a proper noun and click the Save push. See screenshot:

v. Then a Microsoft Outlook dialog box pops upward, delight click the OK button.

Now the selected email with all its attachments is saved into a unmarried PDF file.

Notation: This VBA script only works for Microsoft Word and Excel attachments.



Related Manufactures:

  • How to employ Command Button to save active worksheet as PDF file in Excel?
  • How to save a worksheet as PDF file and electronic mail it every bit an attachment through Outlook?
  • How to salve pick or entire workbook every bit PDF in Excel?

Kutools for Outlook - Brings 100 Advanced Features to Outlook, and Make Work Much Easier!

  • Auto CC/BCC by rules when sending email; Car Forward Multiple Emails by custom; Motorcar Reply without exchange server, and more automatic features...
  • BCC Warning - testify bulletin when you try to reply all if your mail address is in the BCC list; Remind When Missing Attachments, and more remind features...
  • Answer (All) With All Attachments in the mail conversation; Reply Many Emails in seconds; Automobile Add together Greeting when reply; Add together Date into subject...
  • Attachment Tools: Manage All Attachments in All Mails, Auto Disassemble, Shrink All, Rename All, Save All... Quick Report, Count Selected Mails...
  • Powerful Junk Emails by custom; Remove Duplicate Mails and Contacts... Enable yous to do smarter, faster and ameliorate in Outlook.

shot kutools outlook kutools tab 1180x121
shot kutools outlook kutools plus tab 1180x121

cookpultooper.blogspot.com

Source: https://www.extendoffice.com/documents/outlook/5032-convert-outlook-email-to-pdf-with-attachments.html

0 Response to "Automatically Convert Email Attachment to Pdf and Upload to Website"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel