0
votes

I am trying to create a macro which will open a new lotus notes mail, attaches certain files to it and copy and paste the body from a stationery mail.

I am stuck in the last part where I have to copy the BODY of the stationery mail and paste it in the new mail which I have created.

Below is the code which I have tried, but only the files are getting attached but unable to copy the body from the stationery

Any Help is appreciated........

isattached = False
Application.ScreenUpdating = False
'Start Lotus Notes Session
Set nSession = CreateObject("Notes.NotesSession")
On Error GoTo err_send
Set nMailDb = nSession.GetDatabase("", "mailin/GBG180.nsf")

' Open the Stationery View
Set nView = nMailDb.GetView("Stationery")
Set nWorkspace = CreateObject("Notes.NotesUIWorkspace")
Set nCursor = nView.GetFirstDocument

Do While Not nCursor Is Nothing
    ' get stationery value
    StationeryName = nCursor.GetItemValue("MailStationeryName")(0)
    ' match form template selection versus stationery
    If StationeryName = St_name Then

        Set nMailDoc = nMailDb.CreateDocument("Memo")
        Set AttachME = nMailDoc.CreateRichTextItem("ATTACHMENT")
        'Open the PDF folder and attach the files
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objFolder = objFSO.GetFolder(PdfPath)
        For Each objFile In objFolder.Files
            Set EmbedObj = AttachME.EmbedObject(1454, "", PdfPath & objFile.Name)
            isattached = True
            Application.Wait (15)
        Next
        subjectname = policy_num & "-" & aname & "-FoS Invoice & Wording" & " " & Format(DateValue(Now()), "YYYY") & "- Confidential"

        If (isattached) Then
            'Set nMailDoc = nWorkspace.EDITDOCUMENT(True, nCursor)
            nMailDoc.Subject = subjectname
        Else
            Set nMailDoc = Nothing
            Set AttachME = Nothing
            Exit Function
        End If
        nMailDoc.Save True, True, False
        Set nMailDoc = Nothing
        Set nCursor = Nothing

        GoTo nMail_OK
    Else
        Set nCursor = nView.GetNextDocument(nCursor)
    End If
Loop
1

1 Answers

4
votes

In Domino there are Default item names to store data in. The Body (inlcuding all attachments) in a mail is always called "Body", and not "ATTACHMENTS" as in your example.

You need to replace these lines

Set AttachME = nMailDoc.CreateRichTextItem("ATTACHMENT")
'Open the PDF folder and attach the files
...

with these

Dim bodyStationary as NotesRichtextItem
'- get the richtext from the stationary
Set bodyStationary = nCursor.GetFirstItem( "Body" )

'- create richtextitem in new document
Set AttachME = nMailDoc.CreateRichTextItem("Body")

'- append the stationary
Call AttachMe.AppendRTItem( bodyStationary )

'- add the attachments
'Open the PDF folder and attach the files
...

If you want to have the attachments above the text of the stationary, just move the AppendRTItem below the Foreach- loop.

Don't forget to add Attachme.AddNewline( 2 ) in that case, as otherwise the text will directly follow the attachments.