Option Explicit
Sub Inviamail(mail As String, file As String, ccmail As String, j As Integer, conta As Integer, rng As Range)
Dim OutApp As Object
Dim OutMail As Object
Dim bodymail As String
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
firma = "C:Users" & fUserName() & "AppDataRoamingMicrosoftSignatures" & Cells(j, 16)
If Dir(firma) <> "" Then
Sign = GetBoiler(firma)
Else
Sign = ""
End If
On Error Resume Next
With OutMail
.from = "indirizzocassetta@condivisa.com"
.To = mail
.cc = Trim(ccmail)
.Subject = Cells(2, 12) & " " & Cells(3, 13)
.BodyFormat = olFormatHTML
bodymail = ""
bodymail = bodymail + Cells(2, 13) + " " + Cells(3, 13) + " "
bodymail = bodymail + " " + RangetoHTML(rng) + "
"
bodymail = bodymail + Cells(4, 13) + " "
bodymail = bodymail + Cells(5, 13) + " "
bodymail = bodymail + Cells(6, 13)
.HTMLbody = bodymail + "
" + Sign
.Send
End With
On Error GoTo errore
Cells(j, 14) = "INVIATA !"
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set OutMail = Nothing
Set OutApp = Nothing
Exit Sub
errore:
Cells(j, 14) = "ERRORE !"
End Sub
-----------------
Option Explicit
Sub Pulsante1_Click()
Dim mail As String
Dim file As String
Dim ccmail As String
Dim j As Integer
Dim conta As Integer
Dim rng As Range
Range("N2:N100000").ClearContents
j = 2
While Trim(Cells(j, 1)) <> ""
conta = Application.WorksheetFunction.CountIf(Range("B:B"), Cells(j, 2))
Set rng = Range(Cells(j, 3), Cells(j + conta - 1, 8))
mail = Cells(j, 9)
ccmail = Cells(j, 10)
Inviamail mail, file, ccmail, j, conta, Union(Range("C1:H1"), rng)
j = j + conta
Wend
End Sub |