charlesrheault
New Member
- Joined
- May 3, 2011
- Messages
- 4
Hello,
I am having an 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 solutions posted here however no matter what value I put into the cell it keep sending the email anyways. Any help would be greatly appreciated.
Thanks
---------------------------------------------------------------
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
I am having an 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 solutions posted here however no matter what value I put into the cell it keep sending the email anyways. Any help would be greatly appreciated.
Thanks
---------------------------------------------------------------
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