Solved

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

Posted on 2014-04-02
3
3,797 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

To Patch or not to Patch? That is the question!

Don't get caught out like thousands of others around the world in the recent Ransomware Fiasco!
Discuss..
- Why it's not a good idea to wait before Patching
- Sensible approaches to Patching discussed
- Add your feedback, comments and suggestions

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Paste Table from Excel VBA to the PowerPoint 2010 18 55
Cannot locate cell 15 42
Excel - Active X Checkboxes Groups 45 36
Excel Index/Match issue 4 17
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

739 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