Private Sub Worksheet_Change(ByVal Target As Range)
Dim x As Long
x = Sheets("Recipients").Range("A" & Rows.Count).End(3).Row
If Target.Column = 2 And Target.Offset(0, 2).Value = "" Then
Target.Offset(0, -1) = Format(Now(), "mm/dd/yy")
End If
If Not Intersect(Target, Columns(4)) Is Nothing Then
Target.Offset(, 1).Formula = "=VLOOKUP(D" & Target.Row & ",Recipients!$A$2:$B$" & x & ",2,false)"
End If
Dim UserName As String
Dim MailDbName As String
Dim Recipient As Variant
Dim ccRecipient As String
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("", Target.Offset(, 1).Value)
MailDoc.SendTo = Recipient
MailDoc.Subject = "Package Received Under Your Name/Dept"
MailDoc.Body = "The Date is " & Target.Offset(, -3) & vbCrLf & "The Tracking No. is " & Target(, -2) & vbCrLf & "The Carrier is " & Target(, -1) & vbCrLf & vbCrLf & stSignature
' Select Workbook to Attach to E-Mail
MailDoc.SaveMessageOnSend = True
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
MsgBox "The e-mail has successfully been created and distributed.", vbInformation
End Sub
Bookmarks