Lotus Notes/Excel multiple addresses

Sarjent

New Member
Joined
Jul 14, 2004
Messages
41
I am using Excel and setup the following code to allow me to email my sheet through Lotus Notes. It works great for a single address but not for more than that. I searched the site and found several suggestions but could not implement one that provided the solution.

background:
email addresses are imported at load time from an SQL query. They are inserted into Sheet1 A1 in this format - EMAIL1, EMAIL2.

Email1 is John Doe
Email2 is Jane Doe
These are internal addresses to Notes.

If I use 2 internet addresses, like john.doe@email.com, jane.doe@email.com the sheet works and sends the both of them an email.


Code:
Sub Lotus_Notes_EMail()
    '   Declare Variables for file and macro setup
    Dim UserName As String
    Dim MailDbName As String
    Dim Maildb As Object
    Dim MailDoc As Object
    Dim AttachME As Object
    Dim Session As Object
    Dim EmbedObj1 As Object
    Dim Attachment As String
    
        
    ActiveWorkbook.Save
        With Application
            .ScreenUpdating = False
            .DisplayAlerts = False
        End With
    
    'Sheets("Sheet1").Visible = True
     '   Application.Goto Reference:="Sheet1"
    ActiveSheet.Copy
    
    '   Name attachment
    Attachment = "C:\Notes Attachment.htm"
    
    With ActiveWorkbook
        .SaveAs Attachment, FileFormat:=xlHtml
    End With
        
    yesno = MsgBox(" This will generate an e-mail confirmation." _
           & vbCrLf & " Do you wish to send the Confirmation?" _
    , vbYesNo + vbInformation, "Confirmation Generation")
    
    Select Case yesno
        Case vbNo
        Exit Sub
    End Select
    Select Case yesno
        Case vbYes
    
    '   Open and locate current LOTUS NOTES User
    Set Session = CreateObject("Notes.NotesSession")
        UserName = Session.UserName
            MailDbName = Left$(UserName, 1) & Right$(UserName, _
            (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
    Set Maildb = Session.GETDATABASE("", MailDbName)
        If Maildb.IsOpen = True Then
            Else
                Maildb.OPENMAIL
        End If
    
    '   Create New Mail and Address Title Handlers
    Set MailDoc = Maildb.CREATEDOCUMENT
    
    MailDoc.Form = "Memo"
    Recipient = Sheets("Sheet1").Range("A1").Value
        MailDoc.SendTo = Recipient
'        MailDoc.CopyTo = Array("A1")
            MailDoc.Subject = "Server Patching Notice"
MailDoc.Body = _
    Replace("Please see the email attachment regarding server patching of:@@" _
            & Join(Application.Transpose(Range([B17], [B36].End(3))), "@") _
                    & "@@Thank you!", "@", vbCrLf)

                          
    '   Select Workbook to Attach to E-Mail
    MailDoc.savemessageonsend = True
        attachment1 = Attachment
    
    If attachment1 <> "" Then
        On Error Resume Next
            Set AttachME = MailDoc.CREATERICHTEXTITEM("attachment1")
            Set EmbedObj1 = AttachME.embedobject(1454, "attachment1", _
            Attachment, "")
        On Error Resume Next
    End If
    
    MailDoc.PostedDate = Now()
        On Error GoTo errorhandler1
    MailDoc.Send 0, Recipient
    
    Set Maildb = Nothing
    Set MailDoc = Nothing
    Set AttachME = Nothing
    Set Session = Nothing
    Set EmbedObj1 = Nothing
    
    '   Routine to Generate a copy if required
'    OnOff = MsgBox("Do you want to save a copy?", _
 '   vbYesNo + vbInformation, "Save Copy?")
    
 '   Select Case OnOff
 '       Case vbNo
 '           ActiveWorkbook.Close
 '       Exit Sub
 '   End Select
 '       Select Case OnOff
    
 '   Case vbYes
 '       Set NewBook = ActiveWorkbook
'            Do
 '               fName = Application.GetSaveAsFilename
  '          Loop Until fName <> False
 '       NewBook.SaveAs Filename:=fName
'   ActiveWorkbook.Close
    
'    End Select
    ActiveWorkbook.Close
    '   Kill the temp file here if necessary
    Kill Attachment
    
    Exit Sub
    
errorhandler1:
    
    Set Maildb = Nothing
    Set MailDoc = Nothing
    Set AttachME = Nothing
    Set Session = Nothing
    Set EmbedObj1 = Nothing
    
    With Application
        .ScreenUpdating = True
        .DisplayAlerts = True
    End With
    
    End Select
ActiveWorkbook.Close
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Thanks for the reply. I did try that suggestion and still does not cooperate witih me.

I think what I need to do is split the single address field up, then try to pass the array through.

I think I'll try to put the addresses into columns using text to columns then set up the array code. Maybe I will have better luck.
 
Upvote 0
ok I got this code to work.
Code:
Dim recip(25) as variant
recip(0) = Sheets("Sheet1").Range("A2").Value
recip(1) = Sheets("Sheet1").Range("B2").Value
recip(2) = Sheets("Sheet1").Range("C2").Value


maildoc.sendto = recip

it came from another site but I thought I'd share. http://www.fabalou.com/VBandVBA/lotusnotesmail.asp

Now the only thing I need to do is script the seperation of addresses.
 
Upvote 0
Yes, well, that was my advice, although I wouldn't use a variant array as such, and if I were to, I'd declare the lower boundary (a string array might be more on target).

In any case, see the VBE help file re: Split Function
 
Upvote 0
ok your other post says this:
Code:
MailDoc.CopyTo = array("you@somewhere.com","urmama@somewhere.com")

so what I could do then is
Code:
Dim recip AS string
recip = Sheets("Sheet1").Range("A2:D2").Value
MailDoc.SendTo = array("recip")

Is that right? I think I need to use your orignal suggestion as a string because the Split function won't work otherwise. I think my head is going to explode..
 
Upvote 0
I am getting tired now, I keep getting a 1004 error but I cant see it.

Code:
Sub Lotus_Notes_EMail()
    '   Declare Variables for file and macro setup
    Dim UserName As String
    Dim MailDbName As String
    Dim Maildb As Object
    Dim MailDoc As Object
    Dim AttachME As Object
    Dim Session As Object
    Dim EmbedObj1 As Object
    Dim Attachment As String
        
    ActiveWorkbook.Save
        With Application
            .ScreenUpdating = False
            .DisplayAlerts = False
        End With
    
    'Sheets("Sheet1").Visible = True
     '   Application.Goto Reference:="Sheet1"
    ActiveSheet.Copy
    
    '   Name attachment
    Attachment = "C:\Notes Attachment.htm"
    
    With ActiveWorkbook
        .SaveAs Attachment, FileFormat:=xlHtml
    End With
          
        
        
    yesno = MsgBox(" This will generate an e-mail confirmation." _
           & vbCrLf & " Do you wish to send the Confirmation?" _
    , vbYesNo + vbInformation, "Confirmation Generation")
    
    Select Case yesno
        Case vbNo
        Exit Sub
    End Select
    Select Case yesno
        Case vbYes
    
    '   Open and locate current LOTUS NOTES User
    Set Session = CreateObject("Notes.NotesSession")
        UserName = Session.UserName
            MailDbName = Left$(UserName, 1) & Right$(UserName, _
            (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
    Set Maildb = Session.GETDATABASE("", MailDbName)
        If Maildb.IsOpen = True Then
            Else
                Maildb.OPENMAIL
        End If
    
    '   Create New Mail and Address Title Handlers
    Set MailDoc = Maildb.CREATEDOCUMENT
    
    MailDoc.Form = "Memo"
    

ActiveSheet.Range("A1").TextToColumns Destination:=Columns("A2:D2"), DataType:=xlDelimited, _
    ConsecutiveDelimiter:=True, Comma:=True

        MailDoc.SendTo = Array("A2:D2")
            MailDoc.Subject = "Server Patching Notice"
MailDoc.Body = _
    Replace("Please see the email attachment regarding server patching of:@@" _
            & Join(Application.Transpose(Range([B17], [B36].End(3))), "@") _
                    & "@@Thank you!", "@", vbCrLf)

                          
    '   Select Workbook to Attach to E-Mail
    MailDoc.savemessageonsend = True
        attachment1 = Attachment
    
    If attachment1 <> "" Then
        On Error Resume Next
            Set AttachME = MailDoc.CREATERICHTEXTITEM("attachment1")
            Set EmbedObj1 = AttachME.embedobject(1454, "attachment1", _
            Attachment, "")
        On Error Resume Next
    End If
    
    MailDoc.PostedDate = Now()
        On Error GoTo errorhandler1
    MailDoc.Send 0, Recipient
    
    Set Maildb = Nothing
    Set MailDoc = Nothing
    Set AttachME = Nothing
    Set Session = Nothing
    Set EmbedObj1 = Nothing
    

    ActiveWorkbook.Close
    '   Kill the temp file here if necessary
    Kill Attachment
    
    Exit Sub
    
errorhandler1:
    
    Set Maildb = Nothing
    Set MailDoc = Nothing
    Set AttachME = Nothing
    Set Session = Nothing
    Set EmbedObj1 = Nothing
    
    With Application
        .ScreenUpdating = True
        .DisplayAlerts = True
    End With
    
    End Select
ActiveWorkbook.Close
End Sub
 
Upvote 0
Check your PM.

Yesterday I sent you a variation of Nate's code that should let you do what you want.

I didn't post it because it's kind of long.

Smitty

(Heya Nate! What happened to Hockey? :unsure: )
 
Upvote 0
Yeah I looked at that yesterday and I couldn't get it to run either. Even on a blank workbook.

I will try again though it may of been brain overload.
 
Upvote 0

Forum statistics

Threads
1,214,517
Messages
6,119,984
Members
448,935
Latest member
ijat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top