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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
Sub test_v3()
On Error GoTo Mysolution:
Dim libdufd As String, datedujour As Date, msgdumail As String, isin As String, Message As String, ListeMail As String
libdufd = Range("D3")
datedujour = FormatDateTime(Date, vbShortDate)
msgdumail = "Fichier de collecte " & libdufd & " au " & datedujour
isin = Range("B3")
Message = "Souhaitez-vous envoyer le fichier ? "
correspondance = "Le CHEMIN DU FICHIER .XLS DANS LEQUEL rech_isin cherche isin"
If Left(isin, 2) = "FR" Then
type_val = 0
Else
type_val = 1
End If
If type_val = 0 Then
Exit Sub
Else
Range("B3").Select
Workbooks.Open (correspondance)
ActiveWorkbook.RunAutoMacros xlAutoOpen
Worksheets("ETR centralisés").Activate 'ETR centralisés est le nom du sheet du fichier correspondance.xls
End If
Range("A1").Activate
Range("A1:A1000").Select
rech_isin = Cells.Find(isin, LookIn:=xlValues).Activate 'Le On Error GoTo Mysolution: est important ici car si le code
'en "B3" n'est pas trouvé dans onglet "ETR centralisés" j'ai une
'error 91
ActiveCell.Select
ActiveCell.Offset(0, 16).Select 'Les adresses email se trouvent dans la colonne Q du sheet ETR centralisés du workbook correspondance
ListeMail = ActiveCell.Value
If ListeMail = "" Then
Rep = MsgBox("Aucun contact n'est paramètré", vbOK)
ActiveWorkbook.Close
Exit Sub
Else
Rep = MsgBox(Message, vbYesNo)
End If
If Rep = vbNo Then
ActiveWorkbook.Close
Exit Sub
End If
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = ListeMail
ActiveWorkbook.Close 'je ferme le fichier correspondance.xls pour attacher au mail le fichier test.xls
.CC = "XXXX@YY.com"
.Subject = "collecte de " & libdufd
.Body = msgdumail
.Attachments.Add ActiveWorkbook.FullName
.display '.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
ActiveWorkbook.Close
Exit Sub
Mysolution:
If Err.Number = 91 Then
Rep = MsgBox("Le code " & isin & " n'est pas renseigné", vbOK)
ActiveWorkbook.Close
ActiveWorkbook.Close
Exit Sub
End If
End Sub |
Partager