+ Reply to Thread
Results 1 to 2 of 2

save publish to PDF then open in Outlook with attachment

  1. #1
    Forum Contributor
    Join Date
    05-14-2015
    Location
    West Yorkshire
    MS-Off Ver
    10
    Posts
    130

    save publish to PDF then open in Outlook with attachment

    Hi, I wonder if anyone can help. I'd like to save a quotation form with a name from a specific cell (RED TEXT) then click a button to open outlook ready to email as an attachment. The form will be sent to many different people and the subject can be the file name. I hope this is enough info.

    I've copy and pasted a macro that I've found on the web but can't get it to work.

    As usual any help would be very much appreciated...

    Save and Publish PDF.xlsx

  2. #2
    Forum Contributor
    Join Date
    05-14-2015
    Location
    West Yorkshire
    MS-Off Ver
    10
    Posts
    130

    Re: save publish to PDF then open in Outlook with attachment

    sorry macro below:

    Sub AttachActiveSheetPDF()
    Dim IsCreated As Boolean
    Dim i As Long
    Dim PdfFile As String, Title As String
    Dim OutlApp As Object

    ' Not sure for what the Title is
    Title = Range("M10")

    ' Define PDF filename
    PdfFile = ActiveWorkbook.FullName
    i = InStrRev(PdfFile, ".")
    If i > 1 Then PdfFile = Left(PdfFile, i - 1)
    PdfFile = PdfFile & "_" & ActiveSheet.Name & ".pdf"

    ' Export activesheet as PDF
    With ActiveSheet
    .ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    End With

    ' Use already open Outlook if possible
    On Error Resume Next
    Set OutlApp = GetObject(, "Outlook.Application")
    If Err Then
    Set OutlApp = CreateObject("Outlook.Application")
    IsCreated = True
    End If
    OutlApp.Visible = True
    On Error GoTo 0

    ' Prepare e-mail with PDF attachment
    With OutlApp.CreateItem(0)

    ' Prepare e-mail
    .Subject = Title
    .To = "..." ' <-- Put email of the recipient here
    .CC = "..." ' <-- Put email of 'copy to' recipient here
    .Body = "Hi," & vbLf & vbLf _
    & "The report is attached in PDF format." & vbLf & vbLf _
    & "Regards," & vbLf _
    & Application.UserName & vbLf & vbLf
    .Attachments.Add PdfFile

    ' Try to send
    On Error Resume Next
    .Send
    Application.Visible = True
    If Err Then
    MsgBox "E-mail was not sent", vbExclamation
    Else
    MsgBox "E-mail successfully sent", vbInformation
    End If
    On Error GoTo 0

    End With

    ' Delete PDF file
    Kill PdfFile

    ' Quit Outlook if it was created by this code
    If IsCreated Then OutlApp.Quit

    ' Release the memory of object variable
    Set OutlApp = Nothing

    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Outlook attachment Open
    By namluke in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-27-2014, 06:21 AM
  2. Open Outlook Attachment into Excel
    By majosum in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-12-2013, 07:38 PM
  3. From Outlook, open a Word attachment, edit it and save as a PDF
    By Richard Buttrey in forum Word Programming / VBA / Macros
    Replies: 0
    Last Post: 07-08-2012, 03:54 AM
  4. From Outlook, open a Word attachment, edit it and save as a PDF
    By Richard Buttrey in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 07-08-2012, 03:54 AM
  5. Open an attachment from an email in Outlook
    By TypicalDru in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2012, 12:34 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1