Bonjour à tous,
j'ai la macro suivante me permettant de générer un envoi de mail avec pièce jointe
Celle-ci va récupérer des données dans plusieurs onglets et me génère un array que je splitte.
tout fonctionne bien jusqu'ici c'est à dire que je récupéré les bonnes informations et les bons fichier à inclure
Result = Split(Mailing(i), "/")
'MsgBox ("Prenom: " & Result(0) & Chr(13) & Chr(10) & "Nom: " & Result(1) & Chr(13) & Chr(10) & "Projet : " & Result(2) & Chr(13) & Chr(10) & "Period: " & Result(3))
Ceci étant dit j'ai désormais un soucis car j'aimerais créer un seul mail avec les différentes personnes et tous les fichiers
une idée svp?
With Olmail
.To = Result(0) & "." & Result(1) & "@mail.fr"
.Subject = "Grant Office Reminders"
.body = "Projet: " & Result(2) & vbCrLf & vbCrLf & "Fin de période: " & fin_periode & vbCrLf & vbCrLf & "Période concernée: " & Result(3) & vbCrLf & vbCrLf & "Ceci est un mail automatique de mon fichier de suivi."
.Attachments.Add (destination & fichier)
.DeleteAfterSubmit = True
' .Send
.display
Sub Grant_Reminders()
Dim spS As Worksheet
Dim spP As Range
Dim la As Range
Dim tblReport() As Variant
Dim project_ID As Variant
Dim period_ID As Variant
Dim acronym_Row As Variant
Dim acronym As Variant
Dim prem As String
Dim i As Long
Dim n As Long
ReDim Mailing(1 To 1) 'Déclaration d'un tableau dynamique (donc redimensionnable)
Const decalage As Integer = 7 '(de A à H)
Const tableName$ = "T_Reports"
Dim Ol As New Outlook.Application
Dim Olmail As MailItem
Dim CurrFile As String
Set Ol = New Outlook.Application
Set Olmail = Ol.CreateItem(olMailItem)
tblReport = Worksheets("Reporting").Range("A:J").Value
For i = 1 To UBound(tblReport)
If tblReport(i, 7) > Now And tblReport(i, 7) <= Now + 55 And tblReport(i, 10) = "N" Then
project_ID = tblReport(i, 1)
period_ID = tblReport(i, 2)
acronym_Row = Application.Match(project_ID, Worksheets("Projects").Range("A:A"), 0)
If Not IsError(acronym_Row) Then
acronym = Worksheets("Projects").Cells(acronym_Row, 3).Value
Set spS = ThisWorkbook.Worksheets("Staff")
Set spP = spS.Range("A1:A" & spS.Range("A" & Rows.Count).End(xlUp).row)
With spP
Set la = .Find(project_ID, LookIn:=xlValues)
If Not la Is Nothing Then
prem = la.Address
Do
n = n + 1
ReDim Preserve Mailing(1 To n) 'Redimentionnement du tableau (ne pas typer)
If la.Offset(0, decalage) = period_ID Then Mailing(n) = spS.Cells(la.row, 4).Value & "/" & spS.Cells(la.row, 3).Value & "/" & acronym & "/" & period_ID
Set la = .FindNext(la)
Loop While la.Address <> prem
End If
End With
End If
End If
Next i
If n = 0 Then
MsgBox "mailing est vide"
Else
For i = 0 To UBound(Mailing)
i = i + 1
Result = Split(Mailing(i), "/")
'MsgBox ("Prenom: " & Result(0) & Chr(13) & Chr(10) & "Nom: " & Result(1) & Chr(13) & Chr(10) & "Projet : " & Result(2) & Chr(13) & Chr(10) & "Period: " & Result(3))
destination = ThisWorkbook.Path & "\Projects_Library\" & Result(2) & "-" & project_ID & "\Reporting\"
fichier = "FH (" & Result(2) & ")-P" & Result(3) & "-" & Result(0) & " " & Result(1) & " (PP)-vierge.xlsm"
With Olmail
.To = Result(0) & "." & Result(1) & "@mail.fr"
.Subject = "Grant Reminders"
.body = "Projet: " & Result(2) & vbCrLf & vbCrLf & "Fin de période: " & fin_periode & vbCrLf & vbCrLf & "Période concernée: " & Result(3) & vbCrLf & vbCrLf & "Ceci est un mail automatique de mon fichier de suivi."
.Attachments.Add (destination & fichier)
.DeleteAfterSubmit = True
' .Send
.display
End With
Next
End If
End Sub