george hart
Board Regular
- Joined
- Dec 4, 2008
- Messages
- 241
Hi all
The code below works fine in that it sends an email via Lotus Notes to recipients in column H based on a condition.
However, my next task is to somehow email persons attaching two documents. The documents in question will need to be selected
Using something like FileNames = Application.GetOpenFilename(MultiSelect:=True) I quess...Any ideas most appreciated
Dim X As Integer
Dim UserName As String
Dim MailDbName As String
Dim Recipient As Variant
Dim Maildb As Object
Dim MailDoc As Object
Dim AttachME As Object
Dim Session As Object
Dim stSignature As String
Dim myDate As Date
myDate = Date
With Application
.ScreenUpdating = False
.DisplayAlerts = False
For X = 2 To Cells(Rows.Count, "H").End(xlUp).Row
If Range("N" & X) <= 90 _
And Range("J" & X) = "" Or Range("N" & X) <= 60 _
And Range("AB" & X) = "No" And Range("J" & X) < Date Then
' 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(Range("H" & X) _
.Value)
ccRecipient = Array("Paul.Sidney@firstgroup.com", "Anne.Vinten@firstgroup.com")
MailDoc.SendTo = Recipient
MailDoc.CopyTo = ccRecipient
MailDoc.Subject = "SM procedure " & Range("C" & X).Value & " is due a review"
MailDoc.body = "Please note that safety procedure " & Range("C" & X).Value _
& " is due a review no later than " & Range("L" & X).Value
MailDoc.SAVEMESSAGEONSEND = True
MailDoc.PostedDate = Now()
On Error GoTo errorhandler1
MailDoc.SEND 0, Recipient
MsgBox "Notification sent to " & Range("H" & X).Value & " Advising that " _
& Range("C" & X).Value & " is due a review by " & Range("L" & X).Value
Set Maildb = Nothing
Set MailDoc = Nothing
Set Session = Nothing
.ScreenUpdating = True
.DisplayAlerts = True
errorhandler1:
Set Maildb = Nothing
Set MailDoc = Nothing
Set Session = Nothing
If Range("H" & X).Value <> "" Then Range("J" & X).Value = Date
End If
Next X
End With
End Sub
Many thanks in advance
The code below works fine in that it sends an email via Lotus Notes to recipients in column H based on a condition.
However, my next task is to somehow email persons attaching two documents. The documents in question will need to be selected
Using something like FileNames = Application.GetOpenFilename(MultiSelect:=True) I quess...Any ideas most appreciated
Dim X As Integer
Dim UserName As String
Dim MailDbName As String
Dim Recipient As Variant
Dim Maildb As Object
Dim MailDoc As Object
Dim AttachME As Object
Dim Session As Object
Dim stSignature As String
Dim myDate As Date
myDate = Date
With Application
.ScreenUpdating = False
.DisplayAlerts = False
For X = 2 To Cells(Rows.Count, "H").End(xlUp).Row
If Range("N" & X) <= 90 _
And Range("J" & X) = "" Or Range("N" & X) <= 60 _
And Range("AB" & X) = "No" And Range("J" & X) < Date Then
' 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(Range("H" & X) _
.Value)
ccRecipient = Array("Paul.Sidney@firstgroup.com", "Anne.Vinten@firstgroup.com")
MailDoc.SendTo = Recipient
MailDoc.CopyTo = ccRecipient
MailDoc.Subject = "SM procedure " & Range("C" & X).Value & " is due a review"
MailDoc.body = "Please note that safety procedure " & Range("C" & X).Value _
& " is due a review no later than " & Range("L" & X).Value
MailDoc.SAVEMESSAGEONSEND = True
MailDoc.PostedDate = Now()
On Error GoTo errorhandler1
MailDoc.SEND 0, Recipient
MsgBox "Notification sent to " & Range("H" & X).Value & " Advising that " _
& Range("C" & X).Value & " is due a review by " & Range("L" & X).Value
Set Maildb = Nothing
Set MailDoc = Nothing
Set Session = Nothing
.ScreenUpdating = True
.DisplayAlerts = True
errorhandler1:
Set Maildb = Nothing
Set MailDoc = Nothing
Set Session = Nothing
If Range("H" & X).Value <> "" Then Range("J" & X).Value = Date
End If
Next X
End With
End Sub
Many thanks in advance