Word > PDF > Email

dantheram

Board Regular
Joined
Aug 27, 2010
Messages
192
Office Version
  1. 365
Platform
  1. Windows
Evening all,

i've nearly cracked this but i'm stuck on the last bit. I need it to send the saved pdf, not the open word doc, any ideas?

VBA Code:
Sub SendAsPDF()
    Dim strFileName As String
    Dim objOutlook  As Object
    Dim objMailItem As Object

    strFileName = Replace(ActiveDocument.FullName, ".docm", ".pdf")
    ActiveDocument.SaveAs FileName:= InputBox("enter name") & ".pdf", FileFormat:=wdFormatText, AddToRecentFiles:=False
    ActiveDocument.ExportAsFixedFormat OutputFileName:=strFileName, _
        ExportFormat:=wdExportFormatPDF

    Set objOutlook = CreateObject("Outlook.Application")
    Set objMailItem = objOutlook.CreateItem(0) ' 0 = olMailItem
    With objMailItem
        .Subject = "My Subject"
        .Body = "My Message"
        .To = "SomeEmailAddress"
        .Attachments.Add strFileName
        .Display
    End With

    Kill strFileName

    Set objMailItem = Nothing
    Set objOutlook = Nothing
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
actually, i dont think i have solved this much.

i need the macro to save the word document, to its current folder path, as what the user specifies via the prompt box and then email a pdf version to an inbox.

Currently its saving to users home directory and as a pdf not a word doc :(
 
Upvote 0
Just remove this line
ActiveDocument.SaveAs FileName:= InputBox("enter name") & ".pdf", FileFormat:=wdFormatText, AddToRecentFiles:=False
and you've cracked it ...
 
Upvote 0

Forum statistics

Threads
1,214,551
Messages
6,120,161
Members
448,948
Latest member
spamiki

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top