Hello,
I am using the below code to automatically email excel reports via Lotus Notes and it works great. My question is that at times I will run this macro and there will be no report to send that day (an error obviously will occur as the macro cant locate the file). Is there an IF, THEN statement I can include in the code so if the file does not exist the macro should simply end? Any help would be appreciated. Thanks!
'Set up the objects required for Automation into lotus notes
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 AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
Dim stSignature As String
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string
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"
'Attach Your Signature
stSignature = Maildb.GetProfileDocument("CalendarProfile") _
.GetItemValue("Signature")(0)
'MailDoc.Recipient = Recipient
Addressee = "Jerad.Pearson@usbank.com"
Recipient = Split(Addressee, ",")
MailDoc.sendto = Recipient
'MailDoc.Recipient = CopyTo
'MailDoc.copyto = "Jerad.Pearson@usbank.com"
'MailDoc.Recipient = BlindCopyTo
'MailDoc.blindcopyto = "Jerad.Pearson@usbank.com"
'MailDoc.Subject = Subject
MailDoc.Subject = "Retail Processing Report"
'MailDoc.Body = BodyText
MailDoc.Body = "Hello, Attached you will find a copy of your Error Report." & stSignature
'MailDoc.SAVEMESSAGEONSEND = SaveIt
MailDoc.SAVEMESSAGEONSEND = True
'Set up the embedded object and attachment and attach it
Attachment = "G:\Share\Financial and Quality Control and Training\Reporting\Transfer Agency\Data Information\Processing Team 1.xls"
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EmbedObject(1454, "", Attachment, "Attachment")
End If
'Send the document
MailDoc.SEND 0, Recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub
Bookmarks