Excel VBA: Run macro based on cell text

NaeNae

New Member
Joined
Aug 5, 2015
Messages
3
Hi all

Please help me, I have been searching all morning on varous sites to produce a macro which will run once a cell value contains certian text.

My spreadsheet basically tracks letters I send out and identifies if we have not had a response by 28 days and in column "Y" it returns the value "Overdue" if that is the case.

What I want is for my code below (which works) to run when the value in Column Y becomes "Overdue".

My spreadsheet consists of headings from B16 to Y16 and data begins from B17:Y17 and down to B595:Y595. I need Excel to identify any lines which contain the word "Overdue" in column Y, then send the email (run the code below) or if Y is blank, move onto the next line. Presumably someone clever can add some code ontop of my macro below to get this working?

I have formula's after column Y which determine who the reminder should be sent to, and supplies the email address to use in column AF.

Many thanks in anticipation,

Tom


Code:
Sub SendNotesMail()
    
        
    Dim Maildb As Object 'The mail database
    Dim UserName As String 'The current users notes name
    Dim MailDbName As String 'The current users notes mail database name
    Dim MailDoc As Object 'The mail document itself
    Dim Session As Object 'The notes session
     
     'Start a session to notes
    Set Session = CreateObject("Notes.NotesSession")
     
      
    UserName = Session.UserName
    MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
     'Open the mail database in notes
     
    Set Maildb = Session.GETDATABASE("", MailDbName)
    If Maildb.IsOpen = True Then
         'Already open for mail
    Else
        Maildb.OPENMAIL
    End If
     
     'Set up the new mail document
    Set MailDoc = Maildb.CREATEDOCUMENT
    MailDoc.Form = "Memo"
    MailDoc.sendto = (Range("AF17"))
    MailDoc.Subject = "DP letter for: " & Range("B17") & "  " & Range("D17") & " is now overdue"
    MailDoc.Body = "Hi " & Range("AE17") & vbNewLine & vbNewLine & "The letter sent for " & Range("B17") & "  " & Range("D17") & " on " & Range("K17") & " is now overdue. Please contact client." & vbNewLine & vbNewLine & "Kind regards," & vbNewLine & vbNewLine & "My name" & vbNewLine & "My job title" & vbNewLine & "My team name" & vbNewLine & "Address line 1" & vbNewLine & "Address line 2" & vbNewLine & "address line 3" & vbNewLine & "address line 4" & vbNewLine & "post code"
    MailDoc.SAVEMESSAGEONSEND = SaveIt
     
       
    MailDoc.SEND 0, Recipient
     'Clean Up
    Set Maildb = Nothing
    Set MailDoc = Nothing
    Set AttachME = Nothing
    Set Session = Nothing
    Set EmbedObj = Nothing
    
    End If
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,223,336
Messages
6,171,524
Members
452,409
Latest member
brychu

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