+ Reply to Thread
Results 1 to 2 of 2

Emailing in VBA Excel

Hybrid View

gclode Emailing in VBA Excel 03-03-2015, 10:30 AM
TMS Re: Emailing in VBA Excel 03-03-2015, 11:24 AM
  1. #1
    Registered User
    Join Date
    03-26-2014
    Location
    Washington
    MS-Off Ver
    Excel 2010
    Posts
    61

    Emailing in VBA Excel

    I have the code listed below to create an email. I want to send it to the email address that matches the value in a specific cell. For example, if cell B14 on Sheets("SINGLE") equals John Doe I want it to find his email address listed in the table Y1:Z20 on the same sheet and send the email to that address. I am not sure how to enter that into this code below. Any help would be appreciated. Thanks.

    Sub Email()
        Dim OutApp As Object
        Dim OutMail As Object
        Dim PDFFile As String
        Dim FilePath As String
        
        FilePath = "C:\Users\Desktop\TEST\Production.pdf"
        
        'Create PDF'
        Sheets("SINGLE").Range("B13:M35").ExportAsFixedFormat Type:=xlTypePDF, fileName:= _
            FilePath _
            , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
            :=False, OpenAfterPublish:=False
            
        'set up outlook'
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
        
        'Create Message'
        On Error Resume Next
        With OutMail
           .BodyFormat = olFormatHTML
            .display
        End With
            strsignature = OutMail.htmlbody
        With OutMail
            .BodyFormat = olFormatHTML
            .display   'Use only during debugging ##############################
            .to = "" 'Insert required address here ########
            .CC = ""
            .BCC = ""
            .Subject = "Production Email" & " - " & Sheets("SINGLE").Range("C1")
            .htmlbody = "" & "Attached is your production for " & Sheets("SINGLE").Range("C1") & "." & vbCr & vbCr & "Please let me know if there are any questions. Thanks!" & vbCr & vbCr & vbCr & vbCr & strsignature
    
            .Attachments.Add FilePath
    
            '.Send      'Uncomment to send e-mail ##############################
        End With
        Kill "C:\Users\Desktop\TEST\Production.pdf"
        On Error GoTo 0
    
        Set OutMail = Nothing
        Set OutApp = Nothing
        
    End Sub

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,649

    Re: Emailing in VBA Excel

    Something like:

    Option Explicit
    
    'I have the code listed below to create an
    'email. I want to send it to the email address
    'that matches the value in a specific cell.
    'For example, if cell B14 on Sheets("SINGLE")
    'equals John Doe I want it to find his email
    'address listed in the table Y1:Z20 on the same
    'sheet and send the email to that address.
    'I am not sure how to enter that into this code
    'below. Any help would be appreciated. Thanks.
    
    Sub sGetMailAddress()
    
    Dim awf As WorksheetFunction: Set awf = WorksheetFunction
    Dim sEmailAddr As String
    
    With Sheets("SINGLE")
        sEmailAddr = awf.VLookup(.Range("B14").Value, _
                                 .Range("Y1:Z20"), _
                                 2, False)
        
    End With
    
    MsgBox sEmailAddr
    
    End Sub

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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. Emailing From Excel
    By dazstarr in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-22-2007, 01:18 PM
  2. emailing in excel
    By artromanov in forum Excel General
    Replies: 1
    Last Post: 03-10-2007, 06:57 AM
  3. Emailing from Excel
    By tanyhart in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-08-2006, 12:57 PM
  4. Emailing Excel?
    By JoeBed in forum Excel General
    Replies: 2
    Last Post: 05-05-2006, 04:16 PM
  5. [SOLVED] Excel Emailing
    By Pat M in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2006, 06:10 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