Send Email - Change Outlook to Lotus Notes

Davix

New Member
Joined
Oct 24, 2013
Messages
4
Hi guys!
recently a friend made for me a macro to send report to my clients about each payment we made to them.
Well, the macro is working perfectly with the MS outlook but i would like to use it with the Lotus Notes.
I found a macro to send emails with the lotus notes on the web but i can't find a way to mix the both codes and make it work.
Thats why im here, asking for some help
wink.gif


The macro below is the one i use to send the report to my clients with outlook


Code:
<code style="margin: 0px; padding: 0px; font-style: inherit;"><benzatotal><benzatotal>
<code style="margin: 0px; padding: 0px; font-style: inherit;">Private Enum eCol  Supplier = 1  SupplierCode  InvoiceNo  Amount  EmailEnd EnumSub fnc()  Dim objOutlook As Object  Dim objMail As Object  Dim strBody As String  Dim lngLast As Long  Dim lngRow As Long  Dim wks As Excel.Worksheet  Dim col As VBA.Collection  Dim str As String  Dim lng As Long  Dim varRow As Variant  Dim alngRows() As Long  Dim dblTotal As Double    Set objOutlook = CreateObject("Outlook.Application")  Set wks = ActiveSheet  Set col = New VBA.Collection  With wks    lngLast = .Cells(.Rows.Count, eCol.Supplier).End(xlUp).Row    On Error Resume Next    For lngRow = 2 To lngLast      str = .Cells(lngRow, eCol.Supplier)      col.Add str, str    Next lngRow    On Error GoTo 0        For lng = 1 To col.Count      Set objMail = objOutlook.CreateItem(0)      objMail.Subject = "Your invoice"      alngRows = fncMatches(col(lng), .Columns(eCol.Supplier))      lngRow = alngRows(1)      objMail.Recipients.Add .Cells(lngRow, eCol.Email)      dblTotal = 0      strBody = ""      strBody = strBody & "Dear " & .Cells(lngRow, eCol.Supplier) & vbNewLine & vbNewLine      strBody = strBody & "I am writing to advise that "      strBody = strBody & "your invoice total is <benzaTotal>" & vbNewLine      For Each varRow In alngRows        strBody = strBody & "Note " & .Cells(varRow, eCol.InvoiceNo) & " - "        strBody = strBody & Format(.Cells(varRow, eCol.Amount), "R$ 0.00") & vbNewLine        dblTotal = dblTotal + .Cells(varRow, eCol.Amount)      Next varRow      strBody = strBody & vbNewLine & "Regards Mr Brown" & vbNewLine      strBody = strBody & "Analyst"      strBody = Replace(strBody, "<benzaTotal>", Format(dblTotal, "R$ 0.00"))      objMail.Body = strBody      objMail.Display      'Se quiser enviar os e-mails ao invés de mostrá-los,      'troque a linha de cima pela abaixo:      '.Send    Next lng    DoEvents  End WithEnd SubPrivate Function fncMatches(var As Variant, ByVal rng As Range) As Long()    Dim lngEle As Long    Dim Temp() As Long    Dim lng As Long    Dim lngTotal As Long    Dim lngMatch As Long        lngTotal = Application.WorksheetFunction.CountIf(rng, var)    If lngTotal = 0 Then        Exit Function    End If    ReDim Temp(1 To lngTotal)        For lng = 1 To lngTotal        lngMatch = fncMatch(var, rng)        Temp(lng) = lngMatch        If rng.Rows.Count - lngMatch + rng(1).Row - 1 > 0 Then            Set rng = rng.Resize(rng.Rows.Count - lngMatch + rng(1).Row - 1).Offset(lngMatch - rng(1).Row + 1)        End If    Next lng        fncMatches = TempEnd FunctionFunction fncMatch(ByVal str As String, ByVal varVetor As Variant) As Long    Dim Temp As Long        On Error Resume Next    Temp = WorksheetFunction.Match(str + 0, varVetor, 0)    If Temp = 0 Then Temp = WorksheetFunction.Match(CStr(str), varVetor, 0)        If TypeName(varVetor) = "Range" Then      Select Case True        Case varVetor.Columns.Count = 1          Temp = Temp + varVetor(1).Row - 1        Case varVetor.Rows.Count = 1          Temp = Temp + varVetor(1).Column - 1        Case Else          Temp = 0      End Select    End If    fncMatch = TempEnd Function
</code></pre></benzatotal></benzatotal></code>

Here is the macro that i've found on the web to send email via Lotus Notes

Code:
[COLOR=#333333]Sub SendNotesMail() [/COLOR]
<code style="margin: 0px; padding: 0px; font-style: inherit;">    Dim Maildb As Object     Dim UserName As String     Dim MailDbName As String     Dim MailDoc As Object     Dim Session As Object     Dim Recipient As String     Dim Subject1 As String     Dim ccRecipient As String      'Start session'    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 the email document'    Set MailDoc = Maildb.CreateDocument     MailDoc.Form = "Memo"      'Critérios para envio'    Recipient = Sheets("plan1").Range("a1").Value     MailDoc.SendTo = Recipient     ccRecipient = Sheets("plan1").Range("a2").Value     MailDoc.CopyTo = ccRecipient     Subject1 = Sheets("plan1").Range("a3").Value     MailDoc.Subject = Subject1     MailDoc.Body = Replace(Join(Application.Transpose(Range([c25], [c47].End(3))), "@") & "@@Thank you,", "@", vbCrLf)     MailDoc.SaveMessageOnSend = True      'Send email'    MailDoc.PostedDate = Now     On Error Goto Audi     Call MailDoc.Send(False) Set Maildb = Nothing: Set MailDoc = Nothing:     Set Session = Nothing     Exit Sub Audi: Set Maildb = Nothing: Set MailDoc = Nothing:     Set Session = NothingEnd Sub  </code></pre>

Ill put in dropbox the file i use as report model.

https://dl.dropboxusercontent.com/u/94046421/Send email.xlsm

Any help will make me happy! thx!
 
Last edited:

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Could you delet any post? please something wrong happened. I didn't mean to do double post
 
Upvote 0

Forum statistics

Threads
1,215,650
Messages
6,126,016
Members
449,280
Latest member
Miahr

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