Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione di dati
Ciao Simone,
Prova questa leggera modifica:
'========>>
Option Explicit
'-------->>
Public Sub InviaMail()
Dim SH As Worksheet
Dim Rng As Range
Dim oApp As Object
Dim OutMail As Object, oMail As Object
Dim strbody As String
Dim titolo As String, prodotto As String
Dim numero As Long, pratica As Long
Dim iRow As Long, LRow As Long
Dim bFlag As Boolean
Const sFoglio As String = "Scadenzario"
Set SH = ThisWorkbook.Sheets(sFoglio)
With SH
LRow = LastRow(SH, .Columns("A:A"), 2)
Set Rng = .Range("A2:A" & LRow)
For iRow = 2 To LRow
If .Cells(iRow, 11).Value = "Spedire" Or .Cells(iRow, 11).Value = "Versare" Then
If .Cells(iRow, 9).Value = .Cells(2, 14).Value Then
bFlag = True
numero = .Cells(iRow, 6).Value
titolo = .Cells(iRow, 5).Value
prodotto = .Cells(iRow, 3).Value
pratica = .Cells(iRow, 1).Value
strbody = strbody & "<BODY style = font-size:11pt; font-family:Calibri; font-type:bold>" & \_
"<font color = #0070C0> <b><br> abbiamo n. " & numero & " " & titolo \_
& " da spedire per il prodotto " & prodotto & " (pratica " & pratica & ")."
End If
End If
Next iRow
End With
If Not bFlag Then
Call MsgBox(Prompt:="Nessun titolo da Spedire/Versare trovato!", \_
Buttons:=vbInformation, \_
Title:="REPORT")
Exit Sub
End If
Set oApp = CreateObject("Outlook.Application")
strbody = "<BODY style = font-size:11pt; font-family:Calibri; font-type:bold>" & \_
"<font color = #0070C0> <b>Ciao B.O.," & strbody \_
& "<br> <br> Controlliamo lo scadenzario e prepariamo la spedizione / il versamento.</font>"
Set oMail = oApp.CreateItem(0)
On Error Resume Next
With oMail
.To = ""
.Subject = "Alert: Titoli da spedire / versare"
.HTMLBody = strbody & .HTMLBody
.CC = ""
.Display
End With
On Error GoTo 0
Set oMail = Nothing
End Sub
'--------->>
Public Function LastRow(SH As Worksheet, _
Optional Rng As Range, \_
Optional minRow As Long = 1)
If Rng Is Nothing Then
Set Rng = SH.Cells
End If
On Error Resume Next
LastRow = Rng.Find(What:="\*", \_
After:=Rng.Cells(1), \_
Lookat:=xlPart, \_
LookIn:=xlFormulas, \_
SearchOrder:=xlByRows, \_
SearchDirection:=xlPrevious, \_
MatchCase:=False).Row
On Error GoTo 0
If LastRow < minRow Then
LastRow = minRow
End If
End Function
'<<========
Ho aggiornato il mio file di prova Simone20220122.xlsm
===
Regards,
Norman