Salut JB,
bon, à l'aveugle, évidemment, ça peut être Tchernobyl, mais, bon...
Que se passe-t-il si tu as 4000 pdf non-"mailables" sur 4001 lignes ? 4000 MsgBox ?
L'enfer !
Répertorier les échecs et les renseigner dans une MsgBox ou ne serait-il pas plus judicieux de souligner d'une couleur les échecs, ou.........
Sub TEST()
'
Dim OutMail As Object, WshShell As Object
Dim S As Shape, xFound As Boolean
Dim I&, nom$, chemin$, sRep$, strbody$, xName$
'
Application.EnableEvents = False
Application.ScreenUpdating = False
'
xName = InputBox("Veuillez saisir votre nom de famille svp :", "Excel")
If xName = "" Then _
MsgBox "Veuillez saisir un nom de famille valide svp.", vbOKOnly + vbCritical, "Excel": _
Exit Sub
'
If xName = "TOTO" Then
X = 0
UFRF.Show 0
' Créer une instance Windows Script pour retrouver le chemin du bureau
Set WshShell = CreateObject("WScript.Shell")
sRep = WshShell.SpecialFolders("Desktop")
Set WshShell = Nothing
Set OutApp = CreateObject("outlook.application")
Application.DisplayAlerts = False
For I = 4 To Range("A" & Rows.Count).End(xlUp).Row
If IsEmpty(Range("H" & I).Value) Then
If Range("I" & I).Value >= 30 Then
nom = Range("A" & I).Value
X = X + 1
UFRF.Label2.Caption = X & " / " & (Sheets("Principale").Range("I1").Value + Sheets("Principale").Range("I2").Value)
UFRF.Repaint
Sheets(nom).ExportAsFixedFormat Type:=xlTypePDF, Filename:=sRep & "\" & nom & ".pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Set OutMail = OutApp.CreateItem(0)
strbody = "ESSAI 1"
'
With OutMail
.Display
.To = ""
.Cc = ""
.Attachments.Add (sRep & "\" & nom & ".pdf")
.Subject = "OBJET 1"
.HtmlBody = strbody & .HtmlBody
.Send
End With
Kill (sRep & "\" & nom & ".pdf")
Set OutMail = Nothing
End If
Else
MsgBox "Valeur inférieure à 30", vbOKOnly + vbInformation, "Excel"
Exit Sub
End If
Next
Unload UFRF
Application.DisplayAlerts = True
Else
MsgBox "Vous ne pouvez pas cliquer sur ce bouton.", vbOKOnly + vbCritical, "Excel"
End If
'
Application.ScreenUpdating = True
Application.EnableEvents = True
'
End Sub
A+