Solved

Excel 2007 VBA Save Word doc as pdf and email via Outlook

Posted on 2014-04-02
3
3,771 Views
Last Modified: 2014-04-09
Hi

What Excel 2007 VBA code would I use to save a Word doc as pdf and email via Outlook
0
Comment
Question by:murbro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 26

Expert Comment

by:ProfessorJimJam
ID: 39971809
see if the code on this link can help you.

http://stott.asia/word-vba-macro-create-doc-to-pdf-email/
0
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 39971830
Try this:
Sub Demo()

    Dim oWord As Object
    Dim oDoc As Object
    
    Dim oOutlook As Object
    Dim oMail As Object
    Dim strbody As String

    Set oWord = CreateObject("Word.Application")
    Set oDoc = oWord.Documents.Open("C:\Documents and Settings\All Users\Desktop\YourFile.docx")

    oDoc.ExportAsFixedFormat OutputFileName:="C:\Documents and Settings\All Users\Desktop\YourFile.pdf", ExportFormat:=wdExportFormatPDF

    oWord.Quit
    Set oWord = Nothing

    Set oOutlook = CreateObject("Outlook.Application")
    Set oMail = oOutlook.CreateItem(0)

    strbody = "This is" & vbNewLine & vbNewLine & _
              "a test."

    On Error Resume Next
    With oMail
        .To = "You@YourServer.com"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .Body = strbody
        .Attachments.Add ("C:\Documents and Settings\All Users\Desktop\YourFile.pdf")
        .Send   'or use .Display
    End With
    On Error GoTo 0

    Set oMail = Nothing
    Set oOutlook = Nothing
    
End Sub

Open in new window

0
 

Author Closing Comment

by:murbro
ID: 39988787
Thanks very much
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question