Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-04-02
3
Medium Priority
?
3,985 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:Murray Brown
3 Comments
 
LVL 27

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 28

Accepted Solution

by:
MacroShadow earned 2000 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:Murray Brown
ID: 39988787
Thanks very much
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article lists the top 5 trialware OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their Exchange server is no longer available or other critical issues with Exchange server or impo…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

971 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