Ciao TIZIANAC1,
ho trovato giá sul sito una macro fantastica che funziona alla perfezione é la seguente:
Tuttavia, io la devo addattare alla mia esigenza e no riesco:
vorrei infatti che ad ogni destinatario fosse inviata, invece che un singolo documento, una cartella contenente pdf.
Ho provato a sostituire al file in nome della cartella ma ancorché compressa non mi funziona la macro.
mi hanno accennato a cicle di mail ma non so proprio come impostarli.
ringrazio antocipatamente chi potra aiutarmi.
e grazie a Norman che mi ha gia aiutata tantissimo.
=========>>
Option Explicit
'--------->>
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim Rng As Range
Dim arrIn As Variant
Dim oOutlook As Object
Dim oMail As Object
Dim sIndirizzo As String
Dim sNome As String
Dim sCognome As String
Dim sTitolo As String
Dim sPercorso As String
Dim sAllegato As String
Dim sbody As String
Dim LRow As Long, i As Long
Const sFoglio As String = "Foglio1" '<<=== Modifica
Const sOggetto As String = "Vote for Trump" '<<=== Modifica
Set WB = ThisWorkbook
Set SH = WB.Sheets(sFoglio)
With SH
LRow = LastRow(SH, .Columns("A:A"))
Set Rng = .Range("A2:F" & LRow)
End With
arrIn = Rng.Value2
Set oOutlook = CreateObject("Outlook.Application")
For i = 1 To UBound(arrIn)
Set oMail = oOutlook.CreateItem(0)
With oMail
sIndirizzo = arrIn(i, 1)
sCognome = arrIn(i, 2)
sNome = arrIn(i, 3)
sTitolo = arrIn(i, 4)
sPercorso = arrIn(i, 5)
sAllegato = arrIn(i, 6)
sbody = "<H3><B>Gentile utente,</B></H3>" & _
"la tua iscrizione al corso XXYY di Volley del " & _
"25 febbraio 2018" & _
" presso l'istituto ZZKK sito in via Padova, 40 a Milano" & _
" è stata registrata." & _
"<br><br>Per confermare l'iscrizione è necessario effettuare" & _
" il pagamento entro e non oltre domenica 18 febbraio 2018." & _
"<br><br>Per qualsiasi chiarimento o dubbio, contatta " & _
"la Segreteria allo 02/xxxxxxxx o scrivi a " & _
"<B>*** L'indirizzo di posta elettronica viene rimosso per motivi di privacy ***</B>" & _
"<br><br>Cordiali saluti<br>" & _
"<br><B>Cognome nome</B><br>" & _
"Segreteria di direzione" & _
"<br>Nome Azienda<br>" & _
"N°telefono<br>" & _
"sito web<br>" & _
"indirizzo mail<br>"
.display
.To = sIndirizzo
.CC = ""
.BCC = ""
.Subject = sOggetto
.HTMLBody = sbody & "<br>" & .HTMLBody
.Attachments.Add sPercorso _
& Application.PathSeparator _
& sAllegato
.Send
End With
Set oMail = Nothing
Next i
Set oMail = Nothing
Set oOutlook = Nothing
End Sub
'--------->>
Public Function LastRow(SH As Worksheet, _
Optional Rng As Range, _
Optional minRow As Long = 1, _
Optional sPassword As String)
Dim bProtected As Boolean
With SH
If Rng Is Nothing Then
Set Rng = .Cells
End If
bProtected = .ProtectContents = True
If bProtected Then
Application.ScreenUpdating = False
.Unprotect Password:=sPassword
End If
End With
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
If bProtected Then
SH.Protect Password:=sPassword, _
UserInterfaceOnly:=True
End If
Application.ScreenUpdating = True
End Function
'<<=========
Supponendo che tutti i file nella directory di interesse debbano essere inviati a ciascuna persona, prova qualcosa del genere:
'=========>>
Option Explicit
'--------->>
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim Rng As Range
Dim arrIn As Variant
Dim oOutlook As Object
Dim oMail As Object
Dim sIndirizzo As String
Dim sNome As String
Dim sCognome As String
Dim sTitolo As String
Dim sPercorso As String
Dim sAllegato As String
Dim sbody As String
Dim sFile As String
Dim LRow As Long, i As Long
Const sFoglio As String = "Foglio1" '<<=== Modifica
Const sOggetto As String = "Vote for Trump" '<<=== Modifica
Const sPath As String = "C:\Pippo" '<<=== Modifica
Set WB = ThisWorkbook
Set SH = WB.Sheets(sFoglio)
With SH
LRow = LastRow(SH, .Columns("A:A"))
Set Rng = .Range("A2:F" & LRow)
End With
arrIn = Rng.Value2
Set oOutlook = CreateObject("Outlook.Application")
For i = 1 To UBound(arrIn)
Set oMail = oOutlook.CreateItem(0)
With oMail
sIndirizzo = arrIn(i, 1)
sCognome = arrIn(i, 2)
sNome = arrIn(i, 3)
sTitolo = arrIn(i, 4)
sPercorso = arrIn(i, 5)
sAllegato = arrIn(i, 6)
sbody = "<H3><B>Gentile utente,</B></H3>" & _
"la tua iscrizione al corso XXYY di Volley del " & _
"25 febbraio 2018" & _
" presso l'istituto ZZKK sito in via Padova, 40 a Milano" & _
" è stata registrata." & _
"<br><br>Per confermare l'iscrizione è necessario effettuare" & _
" il pagamento entro e non oltre domenica 18 febbraio 2018." & _
"<br><br>Per qualsiasi chiarimento o dubbio, contatta " & _
"la Segreteria allo 02/xxxxxxxx o scrivi a " & _
"<B>******@outlook.com</B>" & _
"<br><br>Cordiali saluti<br>" & _
"<br><B>Cognome nome</B><br>" & _
"Segreteria di direzione" & _
"<br>Nome Azienda<br>" & _
"N°telefono<br>" & _
"sito web<br>" & _
"indirizzo mail<br>"
.display
.To = sIndirizzo
.CC = ""
.BCC = ""
.Subject = sOggetto
.HTMLBody = sbody & "<br>" & .HTMLBody
sFile = Dir(sPath & "*.*")
Do While Len(sFile) > 0
.Attachments.Add sPath & sFile
sFile = Dir
Loop
.Send
End With
Set oMail = Nothing
Next i
Set oMail = Nothing
Set oOutlook = Nothing
End Sub
'--------->>
Public Function LastRow(SH As Worksheet, _
Optional Rng As Range, _
Optional minRow As Long = 1, _
Optional sPassword As String)
Dim bProtected As Boolean
With SH
If Rng Is Nothing Then
Set Rng = .Cells
End If
bProtected = .ProtectContents = True
If bProtected Then
Application.ScreenUpdating = False
.Unprotect Password:=sPassword
End If
End With
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
If bProtected Then
SH.Protect Password:=sPassword, _
UserInterfaceOnly:=True
End If
Application.ScreenUpdating = True
End Function
'<<=========
===
Regards,
Norman
