VBA formule dans corps de mail

Bonsoir,

J'aurai pour requête d'effectuer une macro de mail dans laquelle le corps de mail serait lié au remplissage d'un tableau.

En effet, à chaque fin de mois je dois effectuer un rappel à plusieurs entités sur des états liquidatifs manquants des centaines d'agents.

J'aimerais donc que le mail puisse indiquer le nom , prénom de l'individu ainsi que le ou les mois manquants.

Ces indications apparaitraient si elle concerne la période entre le premier mois d'année 2019 et la fin de démission/ou le mois en m-1. Car j'envoie le rappel au mois m.

Exemple de raisonnement: Pour un mail envoyé au TGI de Meaux au SIEGE, la macro regarde dans la liste qui travaille dans ces critères puis extrait ceux qui durant leur période d'emploi en 2019 n'ont pas fournis un état et indique le ou les mois en question

exemple: Sulk Viano pour un contrat du 25/08/2018 au 25/06/2019 n'a fourni que 5 états mensuels sur les 6. Le manquant est au mois de mai. Le rendu serait - Sulk Viano: Mai 2019

Pour Vincent Taeo pour un contrat du 01/03/2019 au 15/02/2020, on observe que tous les états sont présents jusqu'a aujourd'hui sauf celui de mars. Le rendu serit - Vincent Taeo :Mars 2019

Qu'en dites vous?

Bonjour,

en ligne 1 il n'y a pas l'année, cela risque de poser un problème pour la détection des défauts !

En effet, l'année afférante est 2019.

Une première étape ... et vérifie les alertes car je ne trouve pas la même chose que toi !

Rebonsoir,

En effet, j'ai omis quelques mois au niveau des alertes. Parcontre, il y aurait-il moyen que les états d'un agent soit sur la même ligne plutot qu'un état manquant par ligne.

Exemple:

Vincent Taeo: Avril 2019, Sept 2019, Octobre 2019, Novembre 2019

au lieu de:

Vincent Taeo: Avril 2019,

Vincent Taeo: Sept 2019,

Vincent Taeo: Octobre 2019,

Vincent Taeo: Novembre 2019

Enfin, j'aimerais ajouter une variable à cette macro à savoir le mois en cours. En effet, il serait plus intéressant que la macro ne ressorte pas les états manquants d'octobre et de novembre étant donné que ces mois ne sont pas encore révolus.

Qu'en dites vous?

J'apprécie le RAS

Regarde si le contenu est ok car j'en perds mon latin ...

Oui c'est quasiment ce que je recherche !! Il faudrait juste que les mois non révolus n'apparaissent pas dans le rendu . Par exemple : on ne devrait pas voir les mois encore les mois d'octobre , novembre et décembre 2019

Encore merci

Option Explicit

Function textemail(k As Integer)
Dim i%, j%, txt$
textemail = ""
With Sheets("Base etats liquidatifs")
    For i = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
        txt = ""
        If .Cells(i, "C") = Cells(k, "C") And .Cells(i, "D") = Cells(k, "D") Then
            For j = 8 To .Cells(1, Columns.Count).End(xlToLeft).Column
                If .Cells(i, j) = "" And DateSerial(Year(.Cells(1, j)), Month(.Cells(1, j)), 1) < Date Then
                    If .Cells(i, "E") < DateSerial(Year(.Cells(1, j)), Month(.Cells(1, j)) + 1, 1) _
                        And .Cells(i, "F") >= DateSerial(Year(.Cells(1, j)), Month(.Cells(1, j)), 1) Then
                        txt = txt & Format(.Cells(1, j), "mmm yyyy") & ", "
                    End If
                End If
            Next j
        End If
        If txt <> "" Then textemail = textemail & "- " & .Cells(i, "A") & " " & .Cells(i, "B") & " : " & Mid(txt, 1, Len(txt) - 2) & "." & vbCrLf
    Next
End With
End Function

Sub alertes()
Dim ligne As Integer, txt As String
Sheets("Corps du mail").Select

    For ligne = 2 To 4
        txt = textemail(ligne)
        If txt <> "" Then
            txt = _
            Cells(ligne, "C") & " " & Cells(ligne, "D") & vbCrLf & vbCrLf & _
            "Bonjour," & vbCrLf & _
            "Il semblerait que les états mensuels des agents suivant nous fassent défaut : " & vbCrLf & _
            txt & "Merci"
        Else
            txt = "RAS pour " & Cells(ligne, "C") & " " & Cells(ligne, "D")
        End If
        MsgBox txt
    Next
End Sub

C'est quasiment ca . Je pense que je peux résoudre mon dernier soucis à savoir ne pas obtenir le mois en cours, exemple vincent Taeo et son mois d'octobre, car j'ai besoin des états seulement le mois écoulé . En tout cas merci pour tout!

Ah oui, désolé, j'aurais dû le prendre en compte

Option Explicit

Function textemail(k As Integer)
Dim i%, j%, txt$
textemail = ""
With Sheets("Base etats liquidatifs")
    For i = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
        txt = ""
        If .Cells(i, "C") = Cells(k, "C") And .Cells(i, "D") = Cells(k, "D") Then
            For j = 8 To .Cells(1, Columns.Count).End(xlToLeft).Column
                If .Cells(i, j) = "" And DateSerial(Year(.Cells(1, j)), Month(.Cells(1, j)) + 1, 1) < Date Then
                    If .Cells(i, "E") < DateSerial(Year(.Cells(1, j)), Month(.Cells(1, j)) + 1, 1) _
                        And .Cells(i, "F") >= DateSerial(Year(.Cells(1, j)), Month(.Cells(1, j)), 1) Then
                        txt = txt & Format(.Cells(1, j), "mmm yyyy") & ", "
                    End If
                End If
            Next j
        End If
        If txt <> "" Then textemail = textemail & "- " & .Cells(i, "A") & " " & .Cells(i, "B") & " : " & Mid(txt, 1, Len(txt) - 2) & "." & vbCrLf
    Next
End With
End Function

Sub alertes()
Dim ligne As Integer, txt As String
Sheets("Corps du mail").Select

    For ligne = 2 To 4
        txt = textemail(ligne)
        If txt <> "" Then
            txt = _
            Cells(ligne, "C") & " " & Cells(ligne, "D") & vbCrLf & vbCrLf & _
            "Bonjour," & vbCrLf & _
            "Il semblerait que les états mensuels des agents suivant nous fassent défaut : " & vbCrLf & _
            txt & "Merci"
        Else
            txt = "RAS pour " & Cells(ligne, "C") & " " & Cells(ligne, "D")
        End If
        MsgBox txt
    Next
End Sub

Pas de soucis par contre j'ai failli oublié quelquechose ! il faudrait aussi prendre en compte la date de démission à la place de la fin du contrat dans les formules si démission il y a . ainsi il ne serait pas pertinent que la macro mentionne le mois d'avril de Linear par exemple

J'espère que c'est la bonne ...

J'ai ajouté ceci :

IIf(.Cells(i, "G") = "", .Cells(i, "F"), .Cells(i, "G"))
Function textemail(k As Integer)
Dim i%, j%, txt$
textemail = ""
With Sheets("Base etats liquidatifs")
    For i = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
        txt = ""
        If .Cells(i, "C") = Cells(k, "C") And .Cells(i, "D") = Cells(k, "D") Then
            For j = 8 To .Cells(1, Columns.Count).End(xlToLeft).Column
                If .Cells(i, j) = "" And DateSerial(Year(.Cells(1, j)), Month(.Cells(1, j)) + 1, 1) < Date Then
                    If .Cells(i, "E") < DateSerial(Year(.Cells(1, j)), Month(.Cells(1, j)) + 1, 1) _
                        And IIf(.Cells(i, "G") = "", .Cells(i, "F"), .Cells(i, "G")) >= DateSerial(Year(.Cells(1, j)), Month(.Cells(1, j)), 1) Then
                        txt = txt & Format(.Cells(1, j), "mmm yyyy") & ", "
                    End If
                End If
            Next j
        End If
        If txt <> "" Then textemail = textemail & "- " & .Cells(i, "A") & " " & .Cells(i, "B") & " : " & Mid(txt, 1, Len(txt) - 2) & "." & vbCrLf
    Next
End With
End Function

Oui , c'est parfait!!!

Gracias Steelson

Rechercher des sujets similaires à "vba formule corps mail"