Bonjour,

Voici le code qui permet l'envoi d'un mail en code vba :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Option Compare Database
Option Explicit
 
Private Sub cmdEnvoyer_Click()
'txtForm
    CDOSendMail txtFrom, txtTo, txtSubject, txtBody, txtAttach
    'txtForm : Mail de l'envoyeur
    'txtTo : Mail de destination
    'txtSubject = Objet
    'txtBody = contenu
    'txtAttach = chemin complet du fichier
End Sub
 
Public Sub CDOSendMail(SendFrom As String, _
                       SendTo As String, _
                       Subject As String, _
                       PlainTextBody As String, _
                       FullPathFileName As String)
Dim cdoMail As CDO.Message
Dim iBp As CDO.IBodyPart ' for IBodyPart on message
Dim iBp1 As CDO.IBodyPart
Dim Flds As ADODB.Fields
Dim Stm  As ADODB.Stream
 
 
    Set cdoMail = New CDO.Message
    With cdoMail
        .From = SendFrom
        .To = SendTo
        .Subject = Subject
        ''Set iBp = .BodyPart
        Set iBp = cdoMail   '??
 
        ' TEXT BODYPART
        ' Add the body part for the text/plain part of message
        Set iBp1 = iBp.AddBodyPart
 
        ' set the fields here
        Set Flds = iBp1.Fields
        Flds("urn:schemas:mailheader:content-type") = "text/plain; charset=""iso-8859-1"""
        Flds.Update
 
        ' get the stream and add the message
        Set Stm = iBp1.GetDecodedContentStream
        Stm.WriteText PlainTextBody
        Stm.Flush
 
 
        ' HTML BODYPART
        ' Do the HTML part here
        Set iBp1 = iBp.AddBodyPart
        ' set the content-type field here
        Set Flds = iBp1.Fields
        Flds("urn:schemas:mailheader:content-type") = "text/html"
        Flds.Update
        ' get the stream and add message HTML text to it
        Set Stm = iBp1.GetDecodedContentStream
        Stm.WriteText "<HTML><H1>this is some content for the body part object</H1></HTML>"
        Stm.Flush
 
        ' Now set the Message object's Content-Type header
        ' to multipart/alternative
        Set Flds = iBp.Fields
        Flds("urn:schemas:mailheader:content-type") = "multipart/alternative"
        Flds.Update
        .AddAttachment FullPathFileName
        .Send
    End With
End Sub
Mon problème se situe dans une certaine partie de ce code (voir en image)et j'aurai aimé savoir pourquoi cela ne fonctionne pas...

Pouvez-m'apporter votre aide s'il vous plait?