Automatic email notification from excel to lotus

voakes

New Member
Joined
Mar 14, 2011
Messages
2
I am wanting to send an automatic email notification to several lotus notes accounts once a specific cell in my excel spreadsheet has been entered in (It does not matter what is entered into the cell).
If someone would be so kind to help me and to do so in lay terms as I am a bit of a newby at this.
Thanks in advance
Vanessa
 

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"
I am wanting to send an automatic email notification to several lotus notes accounts once a specific cell in my excel spreadsheet has been entered in (It does not matter what is entered into the cell).
If someone would be so kind to help me and to do so in lay terms as I am a bit of a newby at this.
Thanks in advance
Vanessa

What is the specific cell? And how many accounts are you wanting to send the notification too?
 
Upvote 0
Welcome to the Board!

Here's some boilerplate code for Lotus Notes:

<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> LotusNotsCoreCode()<br>    <SPAN style="color:#007F00">'     Send an e-mail & attachment using Lotus Not(s)</SPAN><br>    <SPAN style="color:#007F00">'     Original Code by Nate Oliver (NateO)</SPAN><br>    <SPAN style="color:#007F00">'     Declare Variables for file and macro setup</SPAN><br><br>    <SPAN style="color:#00007F">Dim</SPAN> UserName <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> MailDbName <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> Recipient <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> ccRecipient <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> ans <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> Attachment1 <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> Maildb <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> MailDoc <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> AttachME <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> Session <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> EmbedObj1 <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN><br><br>    <SPAN style="color:#00007F">With</SPAN> Application<br>        .ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>        .DisplayAlerts = <SPAN style="color:#00007F">False</SPAN><br><br>      <SPAN style="color:#007F00">' Open and locate current LOTUS NOTES User</SPAN><br>    <br>        <SPAN style="color:#00007F">Set</SPAN> Session = CreateObject("Notes.NotesSession")<br>            UserName = Session.UserName<br>        MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"<br>        <SPAN style="color:#00007F">Set</SPAN> Maildb = Session.GetDatabase("", MailDbName)<br>        <SPAN style="color:#00007F">If</SPAN> Maildb.IsOpen = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>        <SPAN style="color:#00007F">Else</SPAN><br>            Maildb.OPENMAIL<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <br>      <SPAN style="color:#007F00">' Create New Mail and Address Title Handlers</SPAN><br>    <br>        <SPAN style="color:#00007F">Set</SPAN> MailDoc = Maildb.CREATEDOCUMENT<br>    <br>        MailDoc.Form = "Memo"<br>        <SPAN style="color:#007F00">'   Select range of e-mail addresses</SPAN><br>        Recipient = Sheets("E-Mail Addresses").Range("A2").Value<br>        MailDoc.SendTo = Recipient<br>        <br>        ans = MsgBox("Would you like to Copy (cc) anyone on this message?" _<br>            , vbQuestion & vbYesNo, "Send Copy")<br>        <br>            <SPAN style="color:#00007F">If</SPAN> ans = vbYes <SPAN style="color:#00007F">Then</SPAN><br>                ccRecipient = InputBox("Please enter the additional recipient's e-mail address" _<br>                    , "Input e-mail address")<br>                MailDoc.CopyTo = ccRecipient<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>                <br>        MailDoc.Subject = "Pending Report"<br>            MailDoc.Body = _<br>        "Attached is a Pending Report.  Please acknowledge receipt."<br>    <br>    <SPAN style="color:#007F00">'   Select Workbook to Attach to E-Mail</SPAN><br>    <br>        MailDoc.SaveMessageOnSend = <SPAN style="color:#00007F">True</SPAN><br>            Attachment1 = ActiveWorkbook.Name<br>    <br>        <SPAN style="color:#00007F">If</SPAN> Attachment1 <> "" <SPAN style="color:#00007F">Then</SPAN><br>            <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">Resume</SPAN> <SPAN style="color:#00007F">Next</SPAN><br>                <SPAN style="color:#00007F">Set</SPAN> AttachME = MailDoc.CREATERICHTEXTITEM("attachment1")<br>                <SPAN style="color:#00007F">Set</SPAN> EmbedObj1 = AttachME.embedobject(1454, "attachment1", ActiveWorkbook.Name, "") <SPAN style="color:#007F00">'</SPAN><br>            <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">Resume</SPAN> <SPAN style="color:#00007F">Next</SPAN><br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <br>        MailDoc.PostedDate = Now()<br>            <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> errorhandler1<br>        MailDoc.SEND 0, Recipient<br>    <br>        <SPAN style="color:#00007F">Set</SPAN> Maildb = <SPAN style="color:#00007F">Nothing</SPAN><br>            <SPAN style="color:#00007F">Set</SPAN> MailDoc = <SPAN style="color:#00007F">Nothing</SPAN><br>                <SPAN style="color:#00007F">Set</SPAN> AttachME = <SPAN style="color:#00007F">Nothing</SPAN><br>            <SPAN style="color:#00007F">Set</SPAN> Session = <SPAN style="color:#00007F">Nothing</SPAN><br>        <SPAN style="color:#00007F">Set</SPAN> EmbedObj1 = <SPAN style="color:#00007F">Nothing</SPAN><br>    <br>        .ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br>        .DisplayAlerts = <SPAN style="color:#00007F">True</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <br>errorhandler1:<br>    <br>        <SPAN style="color:#00007F">Set</SPAN> Maildb = <SPAN style="color:#00007F">Nothing</SPAN><br>            <SPAN style="color:#00007F">Set</SPAN> MailDoc = <SPAN style="color:#00007F">Nothing</SPAN><br>                <SPAN style="color:#00007F">Set</SPAN> AttachME = <SPAN style="color:#00007F">Nothing</SPAN><br>            <SPAN style="color:#00007F">Set</SPAN> Session = <SPAN style="color:#00007F">Nothing</SPAN><br>        <SPAN style="color:#00007F">Set</SPAN> EmbedObj1 = <SPAN style="color:#00007F">Nothing</SPAN><br>    <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

To activate it you'll want a change event. And here's some boilerplate change event code you can use to call the e-mail code when your cell changes:

<font face=Calibri><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)<br>    <SPAN style="color:#007F00">'   Code goes in the Worksheet specific module</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> rng <SPAN style="color:#00007F">As</SPAN> Range<br>        <SPAN style="color:#007F00">'   Set Target Range, i.e. Range("A1, B2, C3"), or Range("A1:B3")</SPAN><br>        <SPAN style="color:#00007F">Set</SPAN> rng = Target.Parent.Range("xxx")<br>             <SPAN style="color:#007F00">'   Only look at single cell changes</SPAN><br>            <SPAN style="color:#00007F">If</SPAN> Target.Count > 1 <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>            <SPAN style="color:#007F00">'   Only look at that range</SPAN><br>            <SPAN style="color:#00007F">If</SPAN> Intersect(Target, rng) <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>            <SPAN style="color:#007F00">'   Action if Condition(s) are met (do your thing here...)</SPAN><br>            <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>

HTH,
 
Upvote 0
Hi John,
The specific cell is A88. Im hoping to have 5 recipients.


I always use Smitty's code as a starting point when sending LOTUS Notes. I think it can be modified like so too achieve most of what you want. But he may very well have better ideas. Also, if you don't have an attachment too send, then you can delete the lines with Attachment1 , EmbedObj1, AttachMe.

Code:
Sub Vanessa()


Dim UserName As String
Dim MailDbName As String
Dim Recipient As Variant
'Dim Attachment1 As String
Dim Maildb As Object
Dim MailDoc As Object
Dim AttachME As Object
Dim Session As Object
'Dim EmbedObj1 As Object
Dim stSignature As String

With Application
.ScreenUpdating = False
.DisplayAlerts = False

' Open and locate current LOTUS NOTES User

Set Session = CreateObject("Notes.NotesSession")
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
Set Maildb = Session.GetDatabase("", MailDbName)
If Maildb.IsOpen = True Then
Else
Maildb.OPENMAIL
End If

' Create New Mail and Address Title Handlers

Set MailDoc = Maildb.CREATEDOCUMENT

MailDoc.Form = "Memo"

stSignature = Maildb.GetProfileDocument("CalendarProfile").GetItemValue("Signature")(0)


' Select range of e-mail addresses
Recipient = Array("Recipient.One@AOL.com", "Recipient.Two@AOL.com", "Recipient.Three@AOL.com", "Recipient.Four@AOL.com", "Recipient.Five@AOL.com")
MailDoc.SendTo = Recipient
MailDoc.Subject = "PLACE YOUR SUBJECT HERE"
MailDoc.Body = "PLACE THE MESSAGE YOU WANT TO SEND HERE" & vbCrLf & vbCrLf & stSignature

' Select Workbook to Attach to E-Mail

MailDoc.SaveMessageOnSend = True
'Attachment1 = "D:\Common\data\......xls" '"C:\YourFile.xls" ' Required File Name

'If Attachment1 <> "" Then
On Error Resume Next
Set AttachME = MailDoc.CREATERICHTEXTITEM("attachment1")
'Set EmbedObj1 = AttachME.embedobject(1454, "attachment1", "D:\Common\data\......xls", "") 'Required File Name
On Error Resume Next
End If

MailDoc.PostedDate = Now()
On Error GoTo errorhandler1
MailDoc.SEND 0, Recipient

Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj1 = Nothing

.ScreenUpdating = True
.DisplayAlerts = True
End With

errorhandler1:

Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj1 = Nothing

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
  
    Dim rng As Range
        
        Set rng = Target.Parent.Range("A88")
 
            If Target.Count > 1 Then Exit Sub

            If Intersect(Target, rng) Is Nothing Then Exit Sub

            Call Vanessa
            
End Sub
 
Upvote 0
The specific cell is A88

Then you'd adjust that here:

Set rng = Target.Parent.Range("A88")

And at the end of the code where it says "Do your thing here", add:

Call LotusNotesCode

Or whatever you decide to name that sub.
 
Upvote 0
Hello,

I am having the same issue, I currently have a script to do the automatic emails and it works. I use a simple button that calls the macro.

Now I am trying to make it work so that there is a general button calling the "email macro" if the employee has not put "ok" next to his name. I tried your solution however now matter what value I put into the cell it keep sending the email anyways. Any help would be greatly appreciated.

Thanks

---------------------------------------------------------------

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Set rng = Target.Parent.Range("A1")
If Target.Count > 1 Then Exit Sub
If Intersect(Target, rng) Is Nothing Then Call charlesrheaultok
End Sub
 
Sub charlesrheaultok()
 
' setting up various objects
Dim Maildb As Object
Dim UserName As String
Dim MailDbName As String
Dim MailDoc As Object
Dim attachME As Object
Dim Session As Object
Dim EmbedObj1 As Object
Dim recipient As String
Dim ccRecipient As String
Dim bccRecipient As String
Dim subject As String
Dim bodytext As String
Dim Attachment1 As String
Dim User As String
 
User = Application.UserName
 
' setting up all sending recipients
recipient = "eployee1@aero.bombardier.com"
'ccRecipient =Someoneelse@Somewhereelse.com
'bccRecipient = ""
subject = "Reminder"
bodytext = "Reminder" 
 
 
'// Make sure all info has been set before sending!
If recipient = vbNullString Or subject = vbNullString Or bodytext = vbNullString Then
MsgBox "Recipient, Subject and or Body Text is NOT SET!", vbCritical + vbInformation
Exit Sub
End If
 
' creating a notes session
Set Session = CreateObject("Notes.NotesSession")
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
Set Maildb = Session.GETDATABASE("", MailDbName)
 
If Maildb.IsOpen <> True Then
On Error Resume Next
Maildb.OPENMAIL
End If
 
Set MailDoc = Maildb.CreateDocument
MailDoc.Form = "Memo"
 
' loading the lotus notes e-mail with the inputed data
With MailDoc
.SendTo = recipient
.copyto = ccRecipient
'.blindcopyto = bccRecipient
.subject = subject
.Body = bodytext
End With
 
' saving message (Change to True if you want to save it)
MailDoc.SaveMessageOnSend = False
 
Attachment1 = ThisWorkbook.Worksheets("Data").Range("B1").Value
If Attachment1 <> "" Then
Set attachME = MailDoc.CreateRichTextItem("Attachment1")
Set EmbedObj1 = attachME.EmbedObject(1454, "", Attachment1, "Attachment")
MailDoc.CreateRichTextItem ("Attachment")
End If
 
' send e-mail
MailDoc.PostedDate = Now()
' if error in attachment or name of recipients
On Error GoTo errorhandler1
 
MailDoc.Send 0, recipient
 
Set Maildb = Nothing
Set MailDoc = Nothing
Set attachME = Nothing
Set Session = Nothing
Set EmbedObj1 = Nothing
 
'Unload Me
Exit Sub
' setting up the error message
errorhandler1:
MsgBox "Incorrect name supplied or the attachment has not been attached," & _
"or your Lotus Notes has not opened correctly. Recommend you open up Lotus Notes" & _
"to ensure the application runs correctly and that a vaild connection exists"
 
Set Maildb = Nothing
Set MailDoc = Nothing
Set attachME = Nothing
Set Session = Nothing
Set EmbedObj1 = Nothing
' unloading the userform
'Unload Me
End Sub
 
Last edited by a moderator:
Upvote 0
If I read you right, you'd need to lose the change event and just use button code.

Code:
Sub SendMail
  charlesrheaultok
End sub

As for validating it based on a cell entry you'd need to be bit more specific as to your layout and what you want done/when.
 
Upvote 0
Hello and thanks for your reply.

Basicly my application is simple yet I lack of knowledge in VB.

Let's say I have 20 persons with each 1 cell that they need to enter "ok".

If I open the excel sheet and I see that let's say 4 persons didn't enter their "ok", I would have a button "notify" that would send an email to all the persons who didn't fill up that cell with "ok".

What I was thinking is if I use a sub route:

If name #1 cell is nothing then call name#1mail
If name #2 cell is nothing then call name#1mail

I am having an hard time figuring out how to do this, could you please guide me.

Thank you very much
 
Upvote 0
See if this gets you started:

<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> foo()<br>    <SPAN style="color:#00007F">Dim</SPAN> c <SPAN style="color:#00007F">As</SPAN> Range<br>        <br>        <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> c <SPAN style="color:#00007F">In</SPAN> Range([B2], Cells(Rows.Count, "B").End(xlUp))<br>            <SPAN style="color:#00007F">If</SPAN> c.Value <> "OK" <SPAN style="color:#00007F">Then</SPAN><br>                SendMail1<br>                MsgBox "Mail sent for " & c.Offset(, -1).Value<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>        <SPAN style="color:#00007F">Next</SPAN> c<br>        <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>

HTH,
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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