Hi All,
My very first question in this forum. I was trying to send mails thru Lotus Notes from Excel. It works fine but I cannot insert pictures to the body of mail. Following lines produce no result at all.
I have posted the same question in www.excelforum.com also
http://www.excelforum.com/excel-programming/784527-inserting-picture-in-lotus-mail-thru-vba.html
Can somebody help? VBA codes I used are all picked from this forum and excelforum.com and I don't have much idea on what went wrong and where.
My very first question in this forum. I was trying to send mails thru Lotus Notes from Excel. It works fine but I cannot insert pictures to the body of mail. Following lines produce no result at all.
Code:
MyPic1.Copy
Set Data = New DataObject
Data.GetFromClipboard
I have posted the same question in www.excelforum.com also
http://www.excelforum.com/excel-programming/784527-inserting-picture-in-lotus-mail-thru-vba.html
Can somebody help? VBA codes I used are all picked from this forum and excelforum.com and I don't have much idea on what went wrong and where.
Code:
Sub SendMailDirect()
Dim Session As Object
Dim Maildb As Object
Dim MailDoc, UIdoc, WorkSpace As Object
Dim MyPic As Object
Dim PeopleToAddress, SendToPeople, CCPeople, BccPeople As String
Dim MailSubject, Subscription01, Subscription02, Subscription03, Subscription04, BodyOfText As String
Dim TheAttachment As String
Dim EmbedObj1 As Object
Dim attachME As Object
Dim DraftOrSend As String
Dim OneCell As Range
Dim SingleAttachment As Variant
Dim MyPic1, Data As Object
Set MyPic1 = ActiveSheet.DrawingObjects
For Each OneCell In Selection.Cells
PeopleToAddress = OneCell.Offset(0, 4).Value
SendToPeople = OneCell.Offset(0, 1).Value
CCPeople = OneCell.Offset(0, 2).Value
BccPeople = OneCell.Offset(0, 3).Value
BodyOfText = OneCell.Offset(0, 6).Value
TheAttachment = OneCell.Offset(0, 0).Value
DraftOrSend = OneCell.Offset(0, 7).Value
MailSubject = OneCell.Offset(0, 5).Value
Subscription01 = ActiveSheet.Range("Subscription01").Value
Subscription02 = ActiveSheet.Range("Subscription02").Value
Subscription03 = ActiveSheet.Range("Subscription03").Value
Subscription04 = ActiveSheet.Range("Subscription04").Value
TheContent = "Dear " & PeopleToAddress & "," & vbNewLine _
& vbNewLine & vbNewLine _
& BodyOfText _
& vbNewLine _
& vbNewLine & "With Regards," & vbNewLine _
& vbNewLine & Subscription01 & vbNewLine _
& Subscription02 & vbNewLine _
& Subscription03 & vbNewLine _
& Subscription04 & vbNewLine
Set Session = CreateObject("Notes.NotesSession")
Set Maildb = Session.GETDATABASE("", "")
If Maildb.IsOpen <> True Then
Maildb.OPENMAIL
End If
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "memo"
MyPic1.Copy
Set Data = New DataObject
Data.GetFromClipboard
With MailDoc
.sendto = SendToPeople
.Subject = MailSubject
.Body = TheContent
.Copyto = CCPeople
.BlindCopyTo = BccPeople
End With
If TheAttachment <> "" Then
Set attachME = MailDoc.CreateRichTextItem("TheAttachment")
If InStr(1, TheAttachment, ",") > 0 Then
For Each SingleAttachment In Split(TheAttachment, ",")
Set EmbedObj1 = attachME.EmbedObject(1454, "", Trim(SingleAttachment), "Attachment")
Next SingleAttachment
Else
Set EmbedObj1 = attachME.EmbedObject(1454, "", TheAttachment, "Attachment")
End If
MailDoc.CreateRichTextItem ("Attachment")
End If
MailDoc.SAVEMESSAGEONSEND = True
If DraftOrSend <> "Send" Then
Call MailDoc.Save(True, False)
MailDoc.RemoveItem ("DeliveredDate")
Call MailDoc.Save(True, False)
Else
MailDoc.PostedDate = Now()
MailDoc.Send 0, recipient
End If
Set objNotesField = Nothing
Set Session = Nothing
Set Maildb = Nothing
Set MailDoc = Nothing
' Optional code to check if email has been sent
' MsgBox "Email Successfully sent to " & PeopleToAddress & Email
Next OneCell
End Sub