Consulting

Results 1 to 7 of 7

Thread: Saving word doc as pdf file and send it as attachement

  1. #1

    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?

    [VBA]Sub SendDocumentAsAttachment()

    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

    End If

    '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

    End If

    '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

    .Display


    End With

    If bStarted Then 'If the macro started Outlook, stop it again.

    oOutlookApp.Quit

    End If

    'Clean up

    Set oItem = Nothing

    Set oOutlookApp = Nothing

    End Sub

    Sub SaveAsDate()

    ChangeFileOpenDirectory ""

    ActiveDocument.SaveAs FileName:="x" & "-" & Format(Now, "dd-mmm-yyyy-hh-mm-ss") & ".doc"

    End Sub

    [/VBA]

  2. #2
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    I can't remember which version of Word you have?

  3. #3
    Quote Originally Posted by Tinbendr
    I can't remember which version of Word you have?
    I am using word 2003.

  4. #4
    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:

    [VBA]
    Sub SendAsPDF()
    ' 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 = "myboss@xrediyh.com"
    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
    ActiveSheet.ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:=Fname

    ' Create Outlook object
    Set OutlookApp = New Outlook.Application

    ' Create Mail Item and send it
    Set MItem = OutlookApp.CreateItem(olMailItem)
    With MItem
    .To = Recipient
    .Subject = Subj
    .Body = Msg
    .Attachments.Add Fname
    .Save 'to Drafts folder
    '.Send
    End With
    Set OutlookApp = Nothing

    ' Delete the file
    Kill Fname
    End Sub
    [/VBA]

    Maybe somebody can change it so that it works with a work doc.

    Thanks in advance

  5. #5
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    This was what I found here on the board.

    If you have the MS add-in, then there might be something on MS site.

  6. #6
    VBAX Regular
    Joined
    Jun 2013
    Posts
    7
    Location
    of course, you can convert word to pdf vb.net, here are some codes you can refer to.
    Imports System.IO
    Imports System.Drawing.Printing
    Imports RasterEdge.Imaging
    Imports RasterEdge.Imaging.Processing
    Imports RasterEdge.Imaging.Conversion

    Dim PDF As New RasterEdgeImaging()

    Public Sub WordConvertToPdf()
    If True Then
    WordInputFile = ("C:/1.docx")
    ImageOutputFile = ImageFormat.pdf
    End If
    End Sub
    doc.Save(@"C:/1.docx", 1, @"C:/1.pdf")

    .net image sdk
    is your best choice.

  7. #7
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Well for your Excel code you have:[VBA] ActiveSheet.ExportAsFixedFormat _
    Type:=xlTypePDF, [/VBA]

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •