Solved

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

Posted on 2014-04-02
3
3,644 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
3 Comments
 
LVL 25

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 26

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
Resolve DNS query failed errors for Exchange
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now