Saving word doc as pdf file and send it as attachement
I was wondering if there's a macro that convert word doc to pdf file and send it as attachement through e-mail.
I am using the following code to send a word doc but how do I make it save the word doc as pdf file and send it as pdf?
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
'You'll need to add the Outlook Object Library to VBA Tools References
Dim oItem As Outlook.MailItem
On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then 'Document has not been saved
ActiveDocument.Save 'so save it
'see if Outlook is running and if so turn your attention there
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then 'Outlook isn't running
'So fire it up
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
'Open a new e-mail message
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem 'and add the detail to it
.To = "" 'send to this address
.CC = ""
'.BCC = ""
.Subject = " per " & Format(Now, "dd-mmm-yyyy-hh-mm-ss") 'This is the message subject
.Body = Mailbody
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue
If bStarted Then 'If the macro started Outlook, stop it again.
Set oItem = Nothing
Set oOutlookApp = Nothing
ActiveDocument.SaveAs FileName:="x" & "-" & Format(Now, "dd-mmm-yyyy-hh-mm-ss") & ".doc"
I can't remember which version of Word you have?
I am using word 2003.
Originally Posted by Tinbendr
There must be a way how to convert a doc to pdf file and send it as attachement.
The following procedure does it with and excel workbook:
' Uses early binding
' Requires a reference to the Outlook Object Library
Dim OutlookApp As Outlook.Application
Dim MItem As Object
Dim Recipient As String, Subj As String
Dim Msg As String, Fname As String
' Message details
Recipient = "firstname.lastname@example.org"
Subj = "Sales figures"
Msg = "Hey boss, here's the PDF file you wanted."
Msg = Msg & vbNewLine & vbNewLine & "-Frank"
Fname = Application.DefaultFilePath & "\" & _
ActiveWorkbook.Name & ".pdf"
' Create the attachment
' Create Outlook object
Set OutlookApp = New Outlook.Application
' Create Mail Item and send it
Set MItem = OutlookApp.CreateItem(olMailItem)
.To = Recipient
.Subject = Subj
.Body = Msg
.Save 'to Drafts folder
Set OutlookApp = Nothing
' Delete the file
Maybe somebody can change it so that it works with a work doc.
Thanks in advance
This was what I found here on the board.
If you have the MS add-in, then there might be something on MS site.
of course, you can convert word to pdf vb.net, here are some codes you can refer to.
Dim PDF As New RasterEdgeImaging()
Public Sub WordConvertToPdf()
If True Then
WordInputFile = ("C:/1.docx")
ImageOutputFile = ImageFormat.pdf
doc.Save(@"C:/1.docx", 1, @"C:/1.pdf")
.net image sdk is your best choice.
Well for your Excel code you have:[VBA] ActiveSheet.ExportAsFixedFormat _
This is what saves it as PDF. I do not know if 2003 has the same option, but if it does, then do the same thing.