Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Nicola,
Ho fatto varie prove e il tuo codice funziona benissimo, ti chiedo l'ultima cortesia.
E' possibile poter allegare il/i file/files a tutti i destinatari scegliendolo con Filedialog senza dover riportare in una cella il percorso ecc.
Prova a sosituire il codice nel modulo standard con la seguente versione nella quale le modifiche sono evidenziate in grassetto:
'=========>>
Option Explicit
Public currWatcher As clsEmailWatcher
'--------->>
Public Sub Invia_Email()
'\ Inserisci un riferimento alla libreria Outlook xx.x Object Library
'\ Alt+F11 Strumenti | Riferimenti
Dim oOutlook As Outlook.Application ' Object
Dim oMail As Outlook.MailItem
Dim WB As Workbook
Dim SH As Worksheet
Dim Rng As Range, rCell As Range
Dim FD As FileDialog
Dim vSelectedItem As Variant
Dim arrAllegati As Variant
Dim sDestinario As String
Dim sCopia As String
Dim sOggetto As String
Dim sMittente As String
Dim sMsg As String
Dim bSend As Boolean
Dim i As Long, j As Long, Ctr As Long
Dim LRow As Long
Const sFoglio As String = "Foglio1" '<<=== Modifica
Set oOutlook = CreateObject("Outlook.Application")
Set WB = ThisWorkbook
Set SH = WB.Sheets(sFoglio)
With SH
LRow = LastRow(SH, .Columns("A:A"))
Set Rng = .Range("A2:A" & LRow)
End With
Set FD = Application.FileDialog(msoFileDialogOpen)
With FD
.AllowMultiSelect = True
.Title = "Seleziona file da allegare"
.Filters.Clear
.Filters.Add "Excel", "*.xls?"
.InitialView = msoFileDialogViewDetails
If .Show = True Then
ReDim arrAllegati(1 To .SelectedItems.Count)
For Each vSelectedItem In .SelectedItems
j = j + 1
arrAllegati(j) = .SelectedItems(j)
Next vSelectedItem
End If
End With
For Each rCell In Rng.Cells
With rCell
sDestinario = .Offset(0, 1).Value
sCopia = .Offset(0, 2).Value
sOggetto = .Offset(0, 3).Value
sMittente = .Offset(0, 4).Value
End With
If sDestinario Like "?*@?*.?*" Then
Set oMail = oOutlook.CreateItem(0)
Set currWatcher = New clsEmailWatcher
Set currWatcher.BoolRange = rCell.Offset(0, 6)
Set currWatcher.DateRange = rCell.Offset(0, 7)
Set currWatcher.TheMail = oMail
On Error Resume Next
With oMail
.To = sDestinario
.CC = sCopia
.BCC = ""
.Subject = sOggetto
.Body = ""
For j = 1 To UBound(arrAllegati)
.Attachments.Add arrAllegati(j)
Next j
.Send
End With
End If
On Error GoTo 0
Set oMail = Nothing
Next rCell
Call MsgBox( _
Prompt:="Invio multimail completato", _
Buttons:=vbInformation, _
Title:="REPORT")
XIT:
Set oMail = Nothing
Set oOutlook = 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
'<<=========
===
Regards,
Norman