I want to embed a PDF into the body of an email using VBA.
Is there code to insert → Object → Create From file? It seems impossible, so I tried to find a workaround.
I created a separate VBA code which takes the PDF, inserts it into a PowerPoint slide as a shape, then saves that PowerPoint as a JPEG. After I embedded the JPEG into Outlook, the quality is terrible.
How could I fix the quality, or do the same thing in Word in hopes that it will be better quality?
Code for Outlook:
Dim R As Range
For Each R In RList
Set EItem = EApp.CreateItem(0)
With EItem
.display
.to = R.Offset(0, 2)
.Subject = "Report Available: " & R.Offset(0, 4)
.Attachments.Add (path & R.Offset(0, 3))
.htmlbody = "Dear " & R & " " & R.Offset(0, 1) & ",</br><br>" & "</br><br>" _
& "Please find your monthly" & " " & "report attached." & " " & Format(Date, "(mm/dd/yyyy)") & _
"</br><br>" & "</br><br>" & "Regards," & "</br><br>" & _
"xxx and xxx" & "</br><br>" & .htmlbody & "<center><img src='C:\Users\xxx\Desktop\pdf slips\TheOpen.pdf.jpg' <div align=center> &"
End With
Next R
Set EApp = Nothing
Set EItem = Nothing
End Sub
Code for PowerPoint:
Sub PDFToPP10()
Dim oSh As Shape
Dim oSl As Slide
Dim sFileName As String
sFileName = "C:\Users\xxx\Desktop\pdf slips\theopen.pdf"
Set oSl = ActivePresentation.Slides(1)
Set oSh = oSl.Shapes.AddOLEObject(Left:=280, _
Top:=0, _
Width:=8.5 * 49, _
Height:=11# * 49, _
FileName:=sFileName, _
Link:=msoFalse)
Dim sImagePath As String
Dim sImageName As String
Dim oSlide As Slide
Dim lScaleWidth As Long
Dim lScaleHeight As Long
On Error GoTo Err_ImageSave
sImagePath = "C:\Users\xxx\Desktop\pdf slips\theopen.pdf"
For Each oSlide In ActivePresentation.Slides
sImageName = TheOpen & ".jpg"
oSlide.Export sImagePath & sImageName, "JPG"
Next oSlide
Err_ImageSave:
If Err <> 0 Then
MsgBox Err.Description
End If
End Sub