PDA

View Full Version : Automatically save Outlook attachment (pptx), convert to PDF and return to sender VBA



dweir247
11-21-2019, 12:33 AM
I'm trying to automate a very mundane task at work which entails the following:

1) I'm the only person in my team with Adobe Pro and as a result, when we are required to send out project proposals to prospective clients, my colleagues will send me a PPT proposal with a marketing video embedded in a slide and ask me to save as PDF and return to them as Adobe Pro allows for this functionality. Its as simple as opening the PPT, saving as Adobe PDF and then replying to the sender with the PDF'd document. As you can imagine, this can become very mundane and i would imagine can easily be automated through the use of VBA (i've also explore the Python avenue)

I've started by getting this VBA code to save an attachment to a desktop folder based on a rule that will only look at incoming emails with the subject line "PDFPROPOSAL" (and to also make sure i'm not bringing in png attachments in email signatures).


Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim sExt As String
saveFolder = "C:\Users\davweir\Documents\Attachments\"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
Set objAtt = Nothing

For Each oatt In Item.Attachments


' Code here to determine extension of oatt.FileName
' If you wanted pptx files
If ext = "pptx" Then
If Dir(DirAtt & oatt.FileName, vbDirectory) = "" Then
oatt.SaveAsFile DirAtt & oatt.FileName
End If
End If
Next
Next
End Sub


Now i need to be able to:

1) Save the pptx as an Adobe PDF (with the same file name but potentially in a different folder)
2) Reply to the sender of the email with the converted PDF doc

I'm a rookie at VBA (so this code is probably not that great) and don't have much experience in using it but would be much appreciated if someone could help me automate this very mundane task!