Results 1 to 10 of 10

Sending PDF with Outlook email

Threaded View

  1. #1
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Sending PDF with Outlook email

    Have to working code that sends a workbook as PDF with outlook mail.I have a address book that it gets the name and email address from,problem is if
    the person is not in address book I have problems. Is there a way to have a input box pop up to insert a email address if its not in main address book? Really
    need to expert advice on this,not even sure if it can be done.
    Thanks Z

    Const rootpath = "C:\Builder\master\temp"
    Const CoName = "Bob's the Builder-"
    
    Dim vinv As String
    Dim vbuilder As String
    Dim vjob As String
     Dim vSaveAs As String
    
    Sub PackageAndSend()
        SaveAsPDF
        Send_Files
         On Error Resume Next
        Kill vSaveAs 'Deletes the PDF file'
    End Sub
    
    Sub SaveAsPDF()
    
        Const OpenPDF = False
        vinv = CleanseString(Range("invoiceone"))
        vbuilder = CleanseString(Range("builder"))
        vjob = CleanseString(Range("C13"))
    
        vSaveAs = rootpath & "\" & CoName & vinv & "-" & vbuilder & "-" & vjob & ".pdf"
    
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
                                        vSaveAs, _
                                        Quality:=xlQualityStandard, _
                                        IncludeDocProperties:=True, _
                                        IgnorePrintAreas:=True, _
                                         From:=1, To:=1, _
                                        OpenAfterPublish:=OpenPDF
    
    End Sub
    
    Sub Send_Files()
    
    
        Dim OutApp As Object
        Dim OutMail As Object
        Dim AddBook As Worksheet
        Dim Found As Range
    
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
        End With
    
        Set AddBook = Sheets("Address Book")
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
    
        vbuilder = Range("builderone")
       Rem Set Found = AddBook.Range("A:A").Find(What:=vbuilder, _
                                              After:=Range("A1"))
    
        currsht = ActiveSheet.Name
        AddBook.Activate
        Set Found = AddBook.Columns("A:A").Find(What:=vbuilder, _
                                                After:=Range("A1"), _
                                                LookIn:=xlValues, _
                                                LookAt:=xlWhole, _
                                                SearchOrder:=xlByColumns, _
                                                SearchDirection:=xlNext, _
                                                MatchCase:=False, SearchFormat:=False)
    
        If Not Found Is Nothing Then
            vEmailAddress = Found.Offset(0, 4)
        End If
    
        vBody = vbuilder & ";" & vbLf
        vBody = vBody & vbLf & vbLf
        vBody = vBody & "See the attached PDF file ." & vbLf
        vBody = vBody & "" & vbLf
        vBody = vBody & "" & vbLf
        vBody = vBody & CoName
    With OutMail
        
            .To = vEmailAddress
            .Subject = CoName & "-" & vinv & "-" & vjob
            .Body = vBody
    
            If Dir(vSaveAs) <> "" Then
                .Attachments.Add vSaveAs
            End If
             If Trim(.To) = "" Then
            MsgBox ("Your trying to sent an Email that is not in the (AddressBook),you must (Open Outlook) and minimized it before you try and send!")
            End If
            
            If Trim(.To) = "" Then
            .send
            Else
            
            .send 'use .send or .display
            End If
        End With
        
        Sheets(currsht).Activate
        Set OutMail = Nothing
        Set OutApp = Nothing
        With Application
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    End Sub
    Last edited by zplugger; 02-22-2015 at 04:37 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. sending outlook email using vba
    By hcyeap in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-20-2014, 05:11 AM
  2. Sending Email with Outlook
    By cyberwerid in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-27-2013, 05:34 PM
  3. Sending Email via Outlook
    By jamsta1972 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-26-2010, 12:46 PM
  4. Sending an email with Outlook Express not Outlook
    By Steven811 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-05-2010, 04:23 AM
  5. Sending Outlook email pop up box
    By jamphan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-23-2007, 03:56 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