Outlook 2010 - Use VBA to send PDF file as body rather than attachment

Hi Experts

Is it possible to use VBA to insert a PDF file as the body of the email (as though using Insert, Object etc)?  Currently I create the file in Word and have VBA code (also in Word) to convert it to a PDF and attach it to that email but would like to make it the body rather than an attachment.

Many thanks
Archie
MonteDelMarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nick67Commented:
Don't bother with the PDF.
Save the Word document out as HTML to a file location
You can then open the HTML as a textstream and blow it into the .HTMLBody of the email.

With objOutlookMsg
            .BodyFormat = olFormatHTML
            Dim ts As Object
            Dim fs as Object
            Set fs = CreateObject("Scripting.FileSystemObject")
            If fs.FileExists("c:\tempPDF\Summary.htm") = False Then
                GoTo skipHTML
            End If
            Set ts = fs.GetFile("c:\tempPDF\Summary.htm").OpenAsTextStream(1, -2)
            .HTMLBody = "<p>This is an automated sending by me as requested. </p>Please respond to myname@somewhere.com with any inquiries.</P><br><br>"
            .HTMLBody = .HTMLBody & ts.ReadAll
End with

skipHTML:

Open in new window


I do this with Excel to get a formatted table into the body of an email and it works very nicely
MonteDelMarAuthor Commented:
Thanks for your reply, Nick.

The original document contains headers and footers with all sorts of info plus some graphics.  It also contains a logo font which the recipient won't have access to.  This is partly why it is created as a PDF.  Is it possible to achieve this when sending as HTML?
Nick67Commented:
The only way to know will be to save the document as HTML and look at it.
How it renders as HTML will be how it renders in the body of the email message.

Currently I create the file in Word

If it doesn't render nicely as HTML, you might need to adjust the creation until it does.
PDF is a very nasty format to tackle from VBA.
MS Word can be the email editor for Outlook 2010
It may be possible to write directly to the mail message in Word native format.
In that case, the PDF part is a red herring :)

Look here
https://msdn.microsoft.com/en-us/library/dd492012(v=office.12).aspx#Outlook2007ProgrammingCh17_UsingWordEditor
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

MonteDelMarAuthor Commented:
It might help if I explain a bit more about how we're using this.  We create a letter in Word and then, if it is to be sent in an email, add letterhead details (header and footer), save as a pdf and attach it to an email. When the recipient open the attachment, it looks like a printed letter would do and they can't modify the content.  There are 5 or 6 different letterheads.
Nick67Commented:
As far as I know, you aren't going to be able to create a read-only mail message body.
And trying to finalize Word to PDF and then pull that back to a mail message body is both a pain-in-the-neck, at best, or close to impossible without Adobe Acrobat installed.

Since you are working with Word already, the best approach is the one lined out in the link I posted.
Instead of working with Word and a Word document, you work with Word-as-editor and your document becomes the mail message

   Dim objOL As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Dim objDoc As Word.Document
    Dim objSel As Word.Selection
    Dim strStamp As String
    On Error Resume Next
    Set objOL = Application
    If objOL.ActiveInspector.EditorType = olEditorWord Then
        Set objDoc = objOL.ActiveInspector.WordEditor
        Set objNS = objOL.Session
        strStamp = "A line of text we want to add to the body"
        Set objSel = objDoc.Windows(1).Selection
        objSel.Move wdStory, -1
        objDoc.Characters(1).InsertBefore _
          strStamp & vbCrLf & vbCrLf
        objSel.Move wdParagraph, 1
    End If
    Set objOL = Nothing
    Set objNS = Nothing

At that point, everything you are presently doing with Word VBA can be done to the mail message.

But it certainly won't be read-only!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MonteDelMarAuthor Commented:
Great.  Thanks for your help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.