Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending Multiple Attachments In Lotus Notes Via VBA

Status
Not open for further replies.

AnotherHiggins

Technical User
Nov 25, 2003
6,259
US
We are switching from GroupWise to Lotus Notes at work.

I have several reports that I format and send out via macros. Everything has been working beautifully with GW, but I'm having some trouble configuring the code for Lotus Notes.

I should note that I'm not really a programmer - I'm completely self-taught on the job and have come about whatever skills I do have because I am a lazy, lazy man who hates routine "busy work".

anyway, I'll attach the basic code I'm using. I found this here on TT and it is working in most cases, but I have a handful of emails that should be sent out with multiple attachments. I can't seem to pass an array through to the code and get it to work.

I've considered copying all files that are to be attached to a temporary holding area, the looping through whatever files are there and attaching each one - but no joy, I just can't figure it out.

Any help would be greatly appreciated!

Code:
Public Sub SendNotesMail(strSavePath, strSubject, strBody, strAddressee)
'Set up the objects required for Automation into lotus notes
    Dim Maildb As Object 'The mail database
    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 'The notes session
    Dim EmbedObj As Object 'The embedded object (Attachment)
    
    'Start a session to notes
    Set Session = CreateObject("Notes.NotesSession")
    
    'Get the sessions username and then calculate the mail file name
    'You may or may not need this as for MailDBname with some systems you
    'can pass an empty string
    UserName = Session.UserName
    MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
    'Open the mail database in notes
    Set Maildb = Session.GETDATABASE("", MailDbName)
     If Maildb.IsOpen = True Then
          'Already open for mail
     Else
         Maildb.OPENMAIL
     End If
    
    'Set up the new mail document
    Set MailDoc = Maildb.CREATEDOCUMENT
    MailDoc.Form = "Memo"
    MailDoc.sendto = strAddressee
    MailDoc.Subject = strSubject
    MailDoc.Body = strBody
    MailDoc.SAVEMESSAGEONSEND = False
    
    'Set up the embedded object and attachment and attach it
    Attachment = strSavePath
    If Attachment <> "" Then
        Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
        Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
'        MailDoc.CREATERICHTEXTITEM ("Attachment")
    
    'Send the document
    MailDoc.Send 0, Recipient
    'Clean Up
    Set Maildb = Nothing
    Set MailDoc = Nothing
    Set AttachME = Nothing
    Set Session = Nothing
    Set EmbedObj = Nothing
End Sub

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ181-2886 before posting.
 
should be sent out with multiple attachments.
Have a look here (Rofeu's post):
thread707-1076807

Hope This Helps, PH.
FAQ219-2884 or FAQ181-2886
 
Thanks, PH.

Sorry it took me a couple of days to post back - I went ahead with the reports that don't have multiple attachments.

Anyway, I can't manage to cram Rofeu's code into mine.

Here is his code from your linked thread:
Code:
Dim SourceFolder As FoundFiles
Dim AttachFile As Variant

Dim Attachment() As String 'The name + full path of the attachment
Dim NameAttachment() As Variant
Dim Y As Integer
ReDim NameAttachment(Y)
ReDim Attachment(Y) As String

For Each AttachFile In SourceFolder
    
    Attachment(Y) = AttachFile
    NameAttachment(Y) = "Attachment" & Y
    Y = Y + 1
    ReDim Preserve Attachment(Y) As String
    ReDim Preserve NameAttachment(Y)
Next

'Set up the embedded object and attachment and attach it

For Y = LBound(Attachment) To UBound(Attachment)
    If Attachment(Y) <> "" Then
        Set AttachME = MailDoc.CREATERICHTEXTITEM(NameAttachment(Y))
        Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment(Y), NameAttachment(Y))
        MailDoc.CREATERICHTEXTITEM (NameAttachment(Y))
    End If
Next

I know that SourceFolder is the result of a FileSearch somewhere earlier in the code (not quoted by Rofeu), but I can't get it to work for me.

I get Object Required at the line
[tab]For Each AttachFile In SourceFolder

I tried to get around it by changing the line to "For Each AttachFile In .FoundFiles". That gets me past that error, but then I get Rich text item Attachment0 already exists at the line,
[tab]MailDoc.CREATERICHTEXTITEM (NameAttachment(Y))


Any tips on how to get this working?

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ181-2886 before posting.
 
Hi,

don't know why it won't work with the SourceFolder variable, but as to that other line:
Code:
MailDoc.CREATERICHTEXTITEM (NameAttachment(Y))

You can take that out completely as the richtextitem is already created by the statement:

Code:
Set AttachME = MailDoc.CREATERICHTEXTITEM(NameAttachment(Y))

Lotus 5 seems to just create it right over the one already there, but I recently went to LN6 and ran into the same issue.

Cheers,

Roel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top