Hello everyone,
Have a bit of a peculiar situation and hoping there is a genius here that can help me. Basically, i have frankensteined some code to create a process in Excel VBA that saves a selected outlook email attachment as a pdf on my hard drive. This code works and saves the PDF to the selected location but the problem is that occasionally with certain PDFs (not all), I get an error message when i try to open the files (see image)
that says: "Adobe Reader could not open .pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)."
If this happened with all PDFs then I would know there is a genuine problem with the code, but i only get this error with about 20% of the PDFs saved using the code - the rest work without issue.
here is the bit of code i am currently using to save the PDFs:
This code saves the PDF attachment into the specified location and opens the file once saved. Does anyone know another method or piece of code i can use to do the same thing but avoid the corrupted, erroneous files from being occasionally created?
Thanks for your help!
Have a bit of a peculiar situation and hoping there is a genius here that can help me. Basically, i have frankensteined some code to create a process in Excel VBA that saves a selected outlook email attachment as a pdf on my hard drive. This code works and saves the PDF to the selected location but the problem is that occasionally with certain PDFs (not all), I get an error message when i try to open the files (see image)
If this happened with all PDFs then I would know there is a genuine problem with the code, but i only get this error with about 20% of the PDFs saved using the code - the rest work without issue.
here is the bit of code i am currently using to save the PDFs:
Code:
For Each olMail In olFldr.Items
For Each olAtt In olMail.Attachments
If (InStr(1, olMail.SenderName, SenderName1) > 0 And InStr(1, olMail.Subject, MailSub) > 0 And intMessage = vbYes) Or (InStr(1, olMail.SenderName, SenderName1) > 0 And InStr(1, olMail.Body, MailSub) > 0 And intMessage = vbYes) Then
sFile = sPath & sName & ".pdf"
olAtt.SaveAsFile sFile
ActiveWorkbook.FollowHyperlink sFile
Sheets("Sheet1").Range("A1:A24").Value = ""
Exit Sub
End If
This code saves the PDF attachment into the specified location and opens the file once saved. Does anyone know another method or piece of code i can use to do the same thing but avoid the corrupted, erroneous files from being occasionally created?
Thanks for your help!
Last edited: