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