Ciao Alessandro,
Prova a sostituire il tuo codice con la seguente versione:
'=========>>
Option Explicit
'--------->>
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim RngTabella As Range
Dim arrTabella As Variant
Dim OutApp As Object
Dim OutMail As Object
Dim sHeader As String, sMsg As String, sFile As String
Dim LRow As Long, i As Long, j As Long
Const sSoggetto As String = "Cartelle in scadenza"
Const sGreeting As String = "All'attenzione di: "
Set WB = ThisWorkbook
Set SH = WB.Sheets("Campione")
With SH
LRow = LastRow(SH, .Columns("A:A"))
Set RngTabella = .Range("A2:L" & LRow)
End With
arrTabella = RngTabella.Value
On Error GoTo 0
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set OutApp = CreateObject("Outlook.Application")
For i = 1 To UBound(arrTabella, 1)
sFile = arrTabella(i, 3) & ".xlsx"
sHeader = arrTabella(i, 4) _
& vbNewLine _
& arrTabella(i, 6) _
& vbNewLine _
& arrTabella(i, 7) _
& vbNewLine _
& arrTabella(i, 8) _
& vbNewLine & vbNewLine _
& sGreeting _
& arrTabella(i, 5)
sMsg = "Ti trasmetto il questionario per la rilevazione " _
& "dei dati utili alla redazione della ????." _
& vbNewLine _
& "Come in precedenza potrai compilarlo a mano e rinviarlo " _
& "via fax, oppure compilarlo, salvarlo e inviarlo via email; " _
& "lo stesso questionario è scaricabile collegandoTi all’indirizzo " _
& arrTabella(i, 12) _
& vbNewLine & vbNewLine _
& "Fiducioso di poter continuare a contare sulla Tua " _
& "collaborazione, attendo le risposte e Ti saluto cordialmente" _
& vbNewLine & vbNewLine _
& "Allegato: " & sFile
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = arrTabella(i, 9)
.CC = arrTabella(i, 10)
.BCC = ""
.Subject = sSoggetto
.body = sHeader & vbNewLine & vbNewLine & sMsg
.Attachments.Add WB.Path & Application.PathSeparator & sFile
.Send
On Error GoTo 0
End With
Set OutMail = Nothing
Next i
On Error GoTo 0
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
'--------->>
Public Function LastRow(SH As Worksheet, _
Optional Rng As Range)
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
End Function
'<<=========
Ho caricato il mio file di prova Alessandro20150622.xlsm a: http://1drv.ms/1FwBTde
===
Regards,
Norman