+ Reply to Thread
Results 1 to 9 of 9

VBA Send Email from Excel (almost complete)

Hybrid View

Craigeeh22 VBA Send Email from Excel... 11-26-2014, 11:42 AM
estratosphere Re: VBA Send Email from Excel... 11-26-2014, 11:45 AM
Craigeeh22 Re: VBA Send Email from Excel... 11-26-2014, 11:51 AM
estratosphere Re: VBA Send Email from Excel... 11-26-2014, 11:53 AM
Craigeeh22 Re: VBA Send Email from Excel... 11-26-2014, 12:00 PM
BigDawg15 Re: VBA Send Email from Excel... 11-26-2014, 12:12 PM
estratosphere Re: VBA Send Email from Excel... 11-27-2014, 05:45 AM
  1. #1
    Registered User
    Join Date
    07-08-2008
    Location
    Hampshire
    Posts
    5

    Exclamation VBA Send Email from Excel (almost complete)

    Hi all,


    I have the attached doc which is almost complete i need the following help

    1, need the VBA to look in column H and where it is blank then send email to the email in B (this bit is working and what is in the email etc is done)
    2,I need it so it doesn't stop at row 3 which it currently does.

    All help would be amazing!!!confused:
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    02-20-2014
    Location
    Wales
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: VBA Send Email from Excel (almost complete)

    Looking in your code, you have the following:

    For r = 2 To 3 'data in rows 2-3
    '       Get the email address
            Email = Cells(r, 2)
    Which is why it would be stopping - you need to set a variable to count the number of used rows and call

    For r = 2 to x

  3. #3
    Registered User
    Join Date
    07-08-2008
    Location
    Hampshire
    Posts
    5

    Re: VBA Send Email from Excel (almost complete)

    Hi thank you for the above so how do i go about that?

  4. #4
    Registered User
    Join Date
    02-20-2014
    Location
    Wales
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: VBA Send Email from Excel (almost complete)

    Here is your new code:

    Sub SendEMail()
        Dim Email As String, Subj As String
        Dim Msg As String, URL As String
        Dim r As Long, s as Long x As Double
        s = ActiveSheet.UsedRange.Rows.Count
        For r = 2 To s 
    '       Get the email address
            Email = Cells(r, 2)
            
    '       Message subject
            Subj = "Deal Registration Expiring" & " " & Cells(r, 4) & " " & "for" & " " & Cells(r, 6)
    
    '       Compose the message
            Msg = ""
            Msg = Msg & "Dear " & Cells(r, 1) & "," & vbCrLf & vbCrLf
            Msg = Msg & "Your deal registration for " & Cells(r, 3) & " " & Cells(r, 4) & " " & Cells(r, 5) & " " & Cells(r, 6) & " " & "is about to expire. Please respond with a brief update and new expected closure if this deal is still live - otherwise this deal will be closed and marked as lost."
    
            Msg = Msg & " " & vbCrLf
            Msg = Msg & "My Name" & vbCrLf
            Msg = Msg & "Registration Manager"
            
    '       Replace spaces with %20 (hex)
            Subj = Application.WorksheetFunction.Substitute(Subj, " ", "%20")
            Msg = Application.WorksheetFunction.Substitute(Msg, " ", "%20")
                    
    '       Replace carriage returns with %0D%0A (hex)
            Msg = Application.WorksheetFunction.Substitute(Msg, vbCrLf, "%0D%0A")
    '       Create the URL
            URL = "mailto:" & Email & "?subject=" & Subj & "&body=" & Msg
    
    '       Execute the URL (start the email client)
            ShellExecute 0&, vbNullString, URL, vbNullString, vbNullString, vbNormalFocus
    
    '       Wait two seconds before sending keystrokes
            Application.Wait (Now + TimeValue("0:00:02"))
            Application.SendKeys "%s"
        Next r
    End Sub

  5. #5
    Registered User
    Join Date
    07-08-2008
    Location
    Hampshire
    Posts
    5

    Re: VBA Send Email from Excel (almost complete)

    First thing that is perfect and worked like a dream but how do i get it to check if there is a YES in Column H first adn if a yes no email is sent if blank then send email? Thank you for your help.

  6. #6
    Registered User
    Join Date
    02-01-2011
    Location
    California, Sacramento
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: VBA Send Email from Excel (almost complete)

    estratosphere,

    Nice code. FYI you missed a comma in the line
    Dim r As Long, s as Long, x As Double
    Regards,

    BigDawg15

  7. #7
    Registered User
    Join Date
    07-08-2008
    Location
    Hampshire
    Posts
    5

    Re: VBA Send Email from Excel (almost complete)

    I did the notice it come up red but luckily I worked the comma out lol Any ideas on the if question above?

  8. #8
    Registered User
    Join Date
    02-20-2014
    Location
    Wales
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: VBA Send Email from Excel (almost complete)

    Quote Originally Posted by BigDawg15 View Post
    estratosphere,

    Nice code. FYI you missed a comma in the line
    Dim r As Long, s as Long, x As Double
    Regards,

    BigDawg15
    Whoops! Thanks for the spot!

+ 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. Macro to send an email when the value in a cell changes to Complete
    By excel wiz in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-04-2014, 06:03 AM
  2. Workflow with signatures (if cell=x then send email, if signed then send email)
    By Kate2811 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-25-2014, 05:37 AM
  3. How to send email from excel using VBA with Cell Range (Including Images) as Email Body
    By Novice_To_Excel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-24-2014, 05:06 AM
  4. Replies: 2
    Last Post: 02-14-2014, 12:03 AM
  5. Automatic send email (without even click send in mail software) with excel vba ??
    By alexnkc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-17-2013, 08:31 PM

Tags for this Thread

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