+ Reply to Thread
Results 1 to 5 of 5

Looping code to pick from 2 lists and send email in Lotus Notes

  1. #1
    Registered User
    Join Date
    05-11-2012
    Location
    Toledo, Ohio
    MS-Off Ver
    Excel 2003
    Posts
    1

    Looping code to pick from 2 lists and send email in Lotus Notes

    Hello new guy to forum and VBA for that matter... but need some help...



    Ok, So I am trying to creat a looping code that will grab emails from 1 list and populate them in my code that I use to send auto send emails in lotus notes, and then pick the attachment location from another list in excel... So essentially I am looking to send 1 specific file (pdf's) to a specific person... than loop to pick the next person in the list and the next location... so the end result would be that I have sent 10 emails with attachments to 10 different recipients with a unique file attached to each. Below is my code that I sue to attach and send emails from excel through Lotus notes...

    'Starting to build email
    Dim oSess As Object
    Dim oDB As Object
    Dim oDoc As Object
    Dim oItem As Object
    Dim direct As Object
    Dim Var As Variant
    Dim flag As Boolean

    Set oSess = CreateObject("Notes.NotesSession")
    Set oDB = oSess.GETDATABASE("", "")
    Call oDB.OPENMAIL
    flag = True
    If Not (oDB.IsOpen) Then flag = oDB.Open("", "")

    If Not flag Then
    MsgBox "Can't open mail file: " & oDB.SERVER & " " & oDB.FILEPATH
    GoTo exit_SendAttachment
    End If
    On Error GoTo err_handler

    'Building Message
    Set oDoc = oDB.CREATEDOCUMENT
    Set oItem = oDoc.CREATERICHTEXTITEM("BODY")
    oDoc.Form = "Memo"
    oDoc.Subject = "Budget File"
    oDoc.sendto = "[email protected]"
    oDoc.body = "whatever I would like to type same message for all recipients."
    oDoc.postdate = Date
    oDoc.SaveMessageOnSend = True

    'Attaching DATABASE
    Call oItem.EmbedObject(1454, "", "H:\example.pdf")
    oDoc.visable = True
    'Sending Message
    oDoc.SEND False
    exit_SendAttachment:
    On Error Resume Next
    Set oSess = Nothing
    Set oDB = Nothing
    Set oDoc = Nothing
    Set oItem = Nothing
    'Done
    Exit Sub
    err_handler:
    If Err.Number = 7225 Then
    MsgBox "File doesn't exist"
    Else
    MsgBox Err.Number & " " & Err.Description
    End If
    On Error GoTo exit_SendAttachment

    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Looping code to pick from 2 lists and send email in Lotus Notes

    Assuming the email addresses are in column A (A2:A11) and the associated attachment file name (including drive letter and folder path) are in the adjacent B cell, you could loop through them like this:
    Please Login or Register  to view this content.
    Post responsibly. Search for excelforum.com

  3. #3
    Registered User
    Join Date
    03-20-2012
    Location
    Toledo, Ohio
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Looping code to pick from 2 lists and send email in Lotus Notes

    That is perfect, I really appreciate it. If I had multiple files that could possibly go to the same person, would you suggest a second email or is doing another attachment difficult?

  4. #4
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Looping code to pick from 2 lists and send email in Lotus Notes

    Assuming a comma-separated list of file names in the B cell:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-20-2012
    Location
    Toledo, Ohio
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Looping code to pick from 2 lists and send email in Lotus Notes

    This is perfect. Marking as solved! EDIT: Or thought I would, won't give me the option...
    Last edited by irishfan43614; 05-29-2012 at 09:50 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1