Solved

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

Posted on 2014-04-02
3
3,847 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
[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:Murray Brown
ID: 39988787
Thanks very much
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Changing a few Outlook Options can help keep you organized!
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

631 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