1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| Sub Transfert()
Dim Plage_de_recherche As Range ' correspond à la plage de recherche
Dim Valeur_cherchée As String ' correspond à ce que l'on cherche
Dim Trouvé As Range ' c'est le résultat de la recherche
Dim La_colonne As Integer ' colonne du mois où il y a "ok"
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Valeur_cherchée = "ORANGE" 'définition de ce que l'on cherche
Set Plage_de_recherche = Sheets("Feuil1").Range("J2:J58") ' définition de la plage de recherche
Set Trouvé = Plage_de_recherche.Find(what:=Valeur_cherchée, LookIn:=xlValues) ' on effectue la recherche : xlvalues car ok est le résultat d'une formule
If Trouvé Is Nothing Then ' si Trouvé = rien c'est qu'on a rien trouvé...
' ce qu'il y a à faire si on ne trouve pas "OK"
Else
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Bonjour Michel," & vbCrLf & _
" " & vbCrLf & _
"La date de péremption de certain documents approche," & vbCrLf & _
"Vérifiez si une nouvelle version à été mise en ligne." & vbCrLf & " " & vbCrLf & _
"Cordialement," & vbCrLf & _
"Excel"
On Error Resume Next
With OutMail
.To = "armand.n@outlook.com"
.CC = ""
.BCC = ""
.Subject = "MISE A JOUR DES DOCUMENTS"
.Body = strbody
'You can add a file like this
'.Attachments.Add ("C:\test.txt")
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
' ce qu'il faut faire si on trouve
End If
End Sub |
Partager