+ Reply to Thread
Results 1 to 14 of 14

Drop down menu to automatically send email

Hybrid View

  1. #1
    Registered User
    Join Date
    02-05-2009
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    Excel 2003
    Posts
    59

    Drop down menu to automatically send email

    Hello,

    I am trying to create a sheet of a list of jobs, I will fill in the sheet and when the job is completed somebody else will select 'Complete' from the drop down menu in column E.

    Is there a way that I can get excel to automatically send an email when 'complete' is selected? I need to send an email to the email address which I have matched to the initials in the 'Raised By' column. I need the email to contain the info from the cells i.e description, ref no. and date raised.

    Thanks!
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Drop down menu to automatically send email

    Hi,

    Try this.

    Place the code in the sheet code:

    
    Private Sub Worksheet_Change(ByVal Target As Range)
         
        Dim Cell As Range
        Dim rngCheck As Range
         
        uRows = Sheets(1).UsedRange.Rows.Count
         
        Set rngCheck = Intersect(Target.EntireRow, Range("E2:J" & uRows))
        If Not rngCheck Is Nothing Then
            For Each Cell In rngCheck.Cells
                If Cell = "Complete" Then
                
                    Dim OutlookApp As Object
                    Dim Mess As Object, Recip
                    Recip = Target.Offset(0, 4)
                   Set OutlookApp = CreateObject("Outlook.Application")
                   Set Mess = OutlookApp.CreateItem(olMailItem)
                   With Mess
                        .Subject = "Subject"
                        .Body = Target.Offset(0, -1) & Chr(10) & Target.Offset(0, -3) & Chr(10) & Target.Offset(0, -4)
                        .To = Recip
                        .Send
                    End With
                    Exit For
                End If
            Next Cell
        End If
        
    End Sub
    Steffen Thomsen

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Drop down menu to automatically send email

    Hi,

    One way would be as per the attached.
    It assumes your email client is MS Outlook. Note Outlook Express will not work.

    In the code module comment out the 'Display instruction when you're happy it's working OK and uncomment the .Send instruction.

    Regards
    Attached Files Attached Files
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    02-05-2009
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    Excel 2003
    Posts
    59

    Re: Drop down menu to automatically send email

    Thanks for the help.

    I have used Richard's way, although I am having a few problems transferring the code from the test sheet to my actual sheet. I.e I will have to add a few more names and email addresses and the data will be in different columns.

    Do you mind explaining what I need to change in order to do this?

    Thanks.

  5. #5
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Drop down menu to automatically send email

    Hi Jonny981,

    You have code in 2 places you need to copy,

    1 - From sheet1 code module
    2 - From Module 1

    These two you need to copy into the respective modules in your workbook.

    The part you need to change to address different cells

    is the following in Sheet1 module

    
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Not Intersect(Target, Range("E:E")) Is Nothing Then
            If Target = "Complete" Then
                Application.EnableEvents = False
                stDesc = Target.Cells(1, 0) 
                Range("LastSel") = Target.Cells(1, -1) ' this is the offset ref for description
                dt = Target.Cells(1, -2) ' this is the offset ref for date
                stRefNo = Target.Cells(1, -3) ' this is offset ref for Ref No
                steMail = Range("eMail")
                Call Module1.eMailCompleted
            
            End If
    
        End If
        Application.EnableEvents = True
    End Sub
    Hope you get it to work

    Steffen Thomsen

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Drop down menu to automatically send email

    Hi,

    The Worksheet Change event currently detects a change in column E - see second line of code below. Change that as appropriate.

    If the columns are in the same relative position you won't need to change anything else in this code. If they are set out differently you'll need to alter the row and column co-ordinates in the "Target.Cells(r,c)" lines of code

    Make sure that you have the three cells, presently M1:M3 named the same. i.e. put the formulae wherever you like but name them "LastSel", "RowNo" and "eMail".

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Not Intersect(Target, Range("E:E")) Is Nothing Then
            If Target = "Complete" Then
                Application.EnableEvents = False
                stDesc = Target.Cells(1, 0)
                Range("LastSel") = Target.Cells(1, -1)
                dt = Target.Cells(1, -2)
                stRefNo = Target.Cells(1, -3)
                steMail = Range("eMail")
                Call Module1.eMailCompleted
            
            End If
    
        End If
        Application.EnableEvents = True
    End Sub

  7. #7
    Forum Contributor
    Join Date
    02-27-2007
    Posts
    156

    Re: Drop down menu to automatically send email

    Richard this would work for me as well...

    Can I ask if there might be a way to this that would summarize by the "Raised By" and then sent either with a button press or perhaps on the save of the worksheet...

    In my example I would have a similar worksheet but it could have 20 entries by 1 person and 6 by someone else and 1 by a 3rd... I'd like to only send 1 email to each person and have their 20, 6 or 1 entry respectively.

    Great example... thanks for your help!!!!

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Drop down menu to automatically send email

    Hi,

    Yes indeed.

    You'd need to hold a list of email addresses.
    You'd then need a macro containing a loop which would automatically filter your data by individual and extract their records to a separate area. Then within the loop call the macro that raises the Outlook email.

    You could either have a button to start this process or make it dependent on an event like the saving or close of the workbook.

    If you need any specific code then upload your workbook with a note as to which records you need to issue.

    Regards

  9. #9
    Forum Contributor
    Join Date
    02-27-2007
    Posts
    156

    Re: Drop down menu to automatically send email

    Sorry guys I didn't realize this especially since it really is the same thing as the original post just an extension of what it does.

  10. #10
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Drop down menu to automatically send email

    I have posted a reply in your thread.

  11. #11
    Registered User
    Join Date
    02-05-2009
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    Excel 2003
    Posts
    59

    Re: Drop down menu to automatically send email

    Thanks again, although If I try to copy and paste anything in the sheet then I get a run time error. any ideas why?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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