Share via

How to attach pdf file in lotus notes mail through vba excel

Anonymous
2016-02-18T03:42:57+00:00

Hi, Friends good morning....

I have developed a macro sheet to send emails through lotus notes, which is working good, but i want to attach some pdf files as attachment, which i am unable to attach.

Seeking your help to attach pdf file in below coding.

Below is my coding..(Now i just want to attach pdf file saved at my desktop at the end of email body)

Function ExceltoLotus1()

Dim Email As String, Subj As String, Msg As String

Dim r As Integer, x As Double

Dim Maildb As Object, UserName As String, MailDbName As String, DomDbName As String

Dim stFileName As String

Dim MailDoc As Object, Session As Object

Set Session = CreateObject("Notes.NotesSession")

UserName = Session.UserName

MailDbName = "mail" & Mid$(UserName, 4, InStr(1, UserName, " ") - 4) & Mid$(UserName, _

    InStr(1, UserName, " ") + 1, InStr(1, UserName, "/") - InStr(1, UserName, " ") - 1) & ".nsf"

Set Maildb = Session.GetDatabase("", MailDbName)

If Maildb.IsOpen = True Then

    Else: Maildb.OPENMAIL

End If

For r = 2 To Range("a1").End(xlDown).Row

Set MailDoc = Maildb.CreateDocument

MailDoc.Form = "Memo"

Email = Cells(r, 3)

Subj = "Attention required-Settlement of Travel Advance"

        Msg = Msg & Range("K" & r) & "" & vbCrLf & vbCrLf

        Msg = Msg & Range("L" & r) & "" & vbCrLf & vbCrLf

        Msg = Msg & "" & vbCrLf & vbCrLf

        Msg = Msg & "Thanks & Regards," & vbCrLf

        Msg = Msg & "abc team" & vbCrLf

        Msg = Msg & "abc Office"

        MailDoc.Principal = "******@abc.com"

MailDoc.sendto = Email

'MailDoc.CopyTo = Whomever

'MailDoc.BlindCopyTo = Whomever

MailDoc.Subject = Subj

MailDoc.Body = Msg

MailDoc.SaveMessageOnSend = True

MailDoc.PostedDate = Now

'Wait two seconds before sending keystrokes

        'Application.Wait (Now + TimeValue("0:00:02"))

        'Application.SendKeys "%s"

On Error GoTo Audi

Call MailDoc.Send(False)

Next r

Set Maildb = Nothing:    Set MailDoc = Nothing:    Set Session = Nothing

Exit Function

Audi:

Set Maildb = Nothing:    Set MailDoc = Nothing:    Set Session = Nothing

End Function

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Vijay A. Verma 104.8K Reputation points Volunteer Moderator
2016-02-18T09:06:04+00:00

Add following lines of code before On Error GoTo Audi. Replace "C:\Excel\1.pdf" appropriately.

Dim Attachment As String

Attachment = "C:\Excel\1.pdf"

If Attachment <> "" Then

On Error Resume Next

Set AttachMe = MailDoc.CREATERICHTEXTITEM("attachment")

Set EmbedObj = AttachMe.embedobject(1454, "", Attachment, "")

On Error GoTo 0

End If

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful