Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 04-03-2018, 06:26 PM
naeemakhtar naeemakhtar is offline Convert MS-Word document to PDF and email Windows 10 Convert MS-Word document to PDF and email Office 2016
Novice
Convert MS-Word document to PDF and email
 
Join Date: Apr 2016
Posts: 8
naeemakhtar is on a distinguished road
Default Convert MS-Word document to PDF and email

Below is the code that I am working with. The code works fine. The macro will save the file and prepare an email to be send with an attachment in MS-Word format.



I would like to revise the code so that after the user clicks a button called 'convert', the document will be saved as a pdf and an email will be prepared similar to the manner of the current code except the attachment will be a pdf format. I do not need to view the pdf prior to it being sent.

The only change to the code is for the attachment to be saved as a pdf prior to the email being prepared.

I am using word 365 pro plus. I do not have any sort of MS-Word to PDF converter. To convert the document, I choose 'pdf' as file type when saving the MS-Word file.

Thanks.


Here is the code:


Code:
Private Sub CommandButton1_Click()
Dim olkApp As Object
Dim strTo As String
Dim strBody As String
Dim strAtt As String
Dim strSubject As String
Dim Opara As Range
Dim LngPara As Long
For LngPara = 1 To ActiveDocument.Paragraphs.Count
Set Opara = ActiveDocument.Paragraphs(LngPara).Range
If Left(LCase(Opara.Text), 3) = "re:" Then
Opara.End = Opara.End - 1
Opara.MoveStartUntil Chr(32)
Opara.Start = Opara.Start + 1
strSubject = Opara.Text
Exit For
End If
Next LngPara
        strBody = "Please see attached file.  If you have any questions, please do not hesitate to contact me."
    strTo = "any@any.com"
    If ActiveDocument.FullName = "" Then
        MsgBox "activedocument not saved, exiting"
        Exit Sub
    Else
        If MsgBox("Save Document?", vbYesNo, "Error") <> vbYes Then Exit Sub
    End If
    strAtt = ActiveDocument.FullName
    
    Set olkApp = CreateObject("outlook.application")
    With olkApp.createitem(0)
        .To = strTo
        .Subject = strSubject
        .body = strBody
        .attachments.Add strAtt
        '.send
        .Display
    End With
    Set olkApp = Nothing
End Sub

Last edited by macropod; 04-03-2018 at 06:41 PM. Reason: Added code tags
Reply With Quote
 

Tags
email, pdf



Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert MS-Word document to PDF and email Why is a Word document coming up as this? How do I convert? zooeyhall Word 2 10-01-2015 06:22 AM
Convert MS-Word document to PDF and email Convert word document to pdf Catty Word VBA 1 12-11-2013 03:57 PM
Convert MS-Word document to PDF and email Convert a word document in an empty one with backgrounds Esgrimidor Word VBA 11 12-03-2012 03:44 PM
Convert MS-Word document to PDF and email PDF to Word(.doc) document not convert correctly gonner Word 1 09-10-2011 03:25 AM
Convert MS-Word document to PDF and email Convert word document to JPEG. The word document may contain headerfooters vijayaram Word 1 12-30-2009 08:25 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:57 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft