Indsæt range fra Excel som Rich Text Body i Lotus Notes email
Hej.Jeg har nedenstående kode, som kan sende emails ud via en Lotus Notes klient, som kører på samme maskine.
Jeg vil gerne kunne åbne en Excel-fil, kopiere et range og indsætte det som body i emailen. (bemærk ikke som en vedhæftet fil). Jeg har med en pil markeret i koden, hvor "Body" i emailen normalt indsættes.
(Lad os i eksemplet sige at regnearket hedder "C:\test.xlsx", Arket hedder "Ark1" og at ranget hedder "A1:D19")
Er der nogen, der kan hjælpe mig?
Public Function SendNotesMail2(Subj As String, Attachment As String, Recipient As String, ccRecipient As String, BodyText As String, SaveIt As Boolean) As Boolean
Dim Maildb As Object
Dim Body As Object
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
Dim EmbedObj As Object
Dim arrToRecipients, arrCCRecipients
Dim rtitem As Object
On Error GoTo ErrHandler
Session = CreateObject("Notes.NotesSession")
UserName = Session.UserName
MailDbName = UserName.Substring(0, 1) & UserName.Substring(UserName.Length - InStr(1, UserName, " ")) & ".nsf"
Maildb = Session.GetDatabase("", MailDbName)
If Maildb.IsOpen = True Then 'Already open for mail
Else
Maildb.OPENMAIL()
End If
MailDoc = Maildb.CreateDocument 'Set up the new mail document
MailDoc.form = "Memo"
arrToRecipients = Split(Recipient, ",")
MailDoc.sendto = arrToRecipients
arrCCRecipients = Split(ccRecipient, ",")
MailDoc.CopyTo = arrCCRecipients
MailDoc.Subject = Subj
rtitem = MailDoc.CreateRichTextItem("Body")
Call rtitem.AppendText(BodyText) ' <--- Her vil jeg gerne have en tilføjelse, der henter et range fra en Excel-fil og indsætter indholdet som body i min email.
MailDoc.SAVEMESSAGEONSEND = SaveIt
If Attachment <> "" Then
AttachME = MailDoc.CreateRichTextItem("Attachment")
EmbedObj = AttachME.EmbedObject(1454, "", Attachment, "Attachment")
End If
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.send(0, Recipient)
Label5.Text = "Mail afsendt!"
Maildb = Nothing
MailDoc = Nothing
AttachME = Nothing
Session = Nothing
EmbedObj = Nothing
rtitem = Nothing
SendNotesMail2 = True
Exit Function
ErrHandler:
SendNotesMail2 = False
MsgBox("FEJL :-(")
End Function