Hi All
I have a problem getting an attachment (variable Site_Path) to attach to an email sent out in lotus notes. I found the below code while searching this forum but when I use it the email sends correctly except for the fact that the excel file i'm sending isnt attached. I have tried debugging and Site_Path contains the path to the file and the filename itself which I assume is correct. So I guess either I have copied the code incorrectly or the Variable Site_Path is incorrect?
Is anybody able to help? Here is the code.
Code
'************************************************************************************************************
'Emails Site File to chosen Recipients in lotus notes
If Select_Sites_Separation.Mail_CheckBox.Value = True Then
' 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 Site_Path As String
' setting up all sending recipients
recipient = Data.Range("D9").Value
ccRecipient = Data.Range("E9").Value
bccRecipient = Data.Range("F9").Value
subject = Data.Range("D21").Value
bodytext = Data.Range("D22").Value & _
vbNewLine & _
Data.Range("D23").Value & _
vbNewLine & _
Data.Range("D24").Value
'// Lets check to see if form is filled in Min req =Recipient, Subject, Body Text
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
MailDoc.SaveMessageOnSend = True
Attachment1 = Site_Path
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 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 If
'*********************************************************************
Display More
Thanks in advance for your help!!
James