Cell value change macro

wildignite

New Member
Joined
May 5, 2009
Messages
6
Is there a way to send an email to a particular recipient if the value in a cell equals their name. For example, Four Names: JOSH, TIM, ALAN, RON. Alright, when an owner, let's say JOSH(in column A row 3) is changed to TIM, I would like to have a macro that automatically sends and email to TIM to tell him a certain task is ready for him. If the names are in the "A" column then the subject would be in the "C" column. I hope I have explained myself properly. I am a novice in writing VB. Please help. Thank You.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hello and welcome to MrExcel.

Based on http://www.rondebruin.nl/mail/change.htm (please read this for where the code goes):

Sheet code:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then Call Smail(Target.Value, Target.Offset(, 2).Value)
End Sub

Module code

Code:
Sub Smail(recip As Variant, subj As Variant)
    Dim iMsg As Object
    Dim iConf As Object
    '    Dim Flds As Variant
    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")
    '    iConf.Load -1    ' CDO Source Defaults
    '    Set Flds = iConf.Fields
    '    With Flds
    '        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    '        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "Fill in your SMTP server here"
    '        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    '        .Update
    '    End With
    With iMsg
        Set .Configuration = iConf
        .To = recip
        .CC = ""
        .BCC = ""
        .From = """Ron"" <ron@something.nl>"
        .Subject = subj
        .TextBody = "xxxx" 'put message here in quotes
        .Send
    End With
    Set iMsg = Nothing
    Set iConf = Nothing
End Sub
 
Upvote 0
I am getting an error on .Send

how do i find my SMTP Server? I know your probably rolling your eyes right about now. I told you I was a novice. Could the address be something like mail.yahoo.com? Where yahoo is my company name.

Is the error linked to me not inputting the needed info for the server?
 
Upvote 0
Which e-mail client do you use? Outlook, Outlook Express, Other...
 
Upvote 0
How would I write this?
PHP:
Sub Mail_with_outlook()
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strto As String, strcc As String, strbcc As String
    Dim strsub As String, strbody As String

 

    Set OutApp = CreateObject("Outlook.Application")

    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0)

 
If Cells = "JOSH" Then
    strto = "jmilton@worxofwood.com"
    strcc = ""
    strbcc = ""
    strsub = "Important message"
    strbody = "Hi there" & vbNewLine & vbNewLine & _
              "Cell A1 is changed"
    End If
    
 

    With OutMail
        .To = strto
        .CC = strcc
        .BCC = strbcc
        .Subject = strsub
        .Body = strbody
        .Send
    End With
Where I have the if/then statement. Can I say if the cell changes to "JOSH" send to this email? And if the cell changes to "RON" send to this email address? And so on. Is this possible?

 
Upvote 0
This code worked for me, of course, before I threw up in it by adding that if then statement. I just wanted to show what I was thinking.
 
Upvote 0
Here is what I am using now. A friend of mine helped me out. But it is still not working. I am getting an error saying that niether the from or to sender is filled out. Do you see anything wrong with this code? I have the wrong email and pass word in there for obvious reasons.


PHP:
Sub Smail(recip As Variant, subj As Variant)
    Dim iMsg As Object
    Dim iConf As Object
    Dim strbody As String
    Dim Flds As Variant


    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")


    iConf.Load -1    ' CDO Source Defaults
    Set Flds = iConf.Fields
    With Flds
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "jmilton@yahoo.com" 'put your email address of your service provider
        .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "jm0055785"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.yahoo.com" 'ex smtp.gmail.com


        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Update
    End With


    'body of email
    strbody = "Hi there i am excel" & vbNewLine & vbNewLine & _
              "my code rocks" & vbNewLine


    With iMsg
        Set .Configuration = iConf
        .To = recip '"jmilton@yahoo.com" 'who ur sending to
        .CC = ""
        .BCC = ""
        .From = """"""
        .Subject = subj
        .TextBody = strbody
        .Send
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,748
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top