Bonjour bigboy, bonjour Qwazerty,

J'ai lu cette discussion.
Le sujet date un peu mais le problème persiste...
Qwazerty, j'ai un problème de déclaration de variable visiblement :
"Erreur d'exécution '424': Objet requis"

Voici mon code (qui envoi un mail après avoir fait une mise en forme d'un tableau dans le mail Notes) :
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
Sub MailRelanceAuto()
 
Dim LeMail As Object
Dim UserName As String
Dim MailDbName As String
Dim BaseMail As Object
Dim Session As Object 'The notes session
Dim Destinataires(0) As String 'si 1 destinataire,
Dim ccDestinataires(2) As String 'si plusieurs personnes en copie jusqu'à 2,
Dim Sujet As String
Dim body As Object
Dim ligdeb As Integer
Dim ligfin As Integer
Dim derligne As Integer
Dim Reference(50) As String
Dim Defaut(50) As String
Dim Action(50) As String
Dim Cible(50) As String
Dim nbcol As Integer
Dim nbrow As Integer
Dim rtpsCols(3) As NotesRichTextStyle
Dim rtpsColsTAGIS(0) As NotesRichTextStyle
Dim sHeaders(3) As String
Dim rtsStyleBarCode As NotesRichTextStyle
Dim rtsTableHeader As NotesRichTextStyle
Dim rtsTableRow As NotesRichTextStyle
Dim rtnav As NotesRichTextNavigator
 
With Sheets("SUIVI CRIMES").Select
    Range("$B$5:$Q$60000").AutoFilter Field:=5
    Range("$B$5:$Q$60000").AutoFilter Field:=14
    Range("$B$5:$Q$60000").AutoFilter Field:=14, Criteria1:="=" 'filtre sur les actions non soldées
 
' Défini les numéro de lignes (début et fin) lors du filtrage sur la colonne G)
    Set plage = [_filterdatabase].Offset(1).Resize(, 1)
    Set plage = plage.Resize(plage.Count - 1).SpecialCells(xlCellTypeVisible)
'-----------------------------------------------------------------------------------------------------
    ' Identifie les destinataires et mails à envoyer
    ligdeb = plage.Row
    ligfin = Range("F" & ligdeb).End(xlDown).Row
    Range("F" & ligdeb & ":F" & ligfin).SpecialCells(xlCellTypeVisible).Copy
    Sheets("Calculs").Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Sheets("Calculs").Range("$A$1:$A$" & ligfin - 5).RemoveDuplicates Columns:=1, Header:=xlNo
    If Sheets("Calculs").Range("A2").Value = "" Then 'détermine la dernière ligne de la liste des destinataires
        derligne = 1
    Else
        derligne = Sheets("Calculs").Range("A1").End(xlDown).Row
    End If
 
    For i = 1 To derligne 'créé le mail et l'envoi pour chaque déstinataire : 1 boucle = 1 destinataire
        Range("$B$5:$Q$60000").AutoFilter Field:=5, Criteria1:=Sheets("Calculs").Range("A" & i).Value 'filtre sur l'action du destinataire
        Set plage = [_filterdatabase].Offset(1).Resize(, 1) 'identifie la plage de lignes visibles après filtre
        Set plage = plage.Resize(plage.Count - 1).SpecialCells(xlCellTypeVisible)
 
        Range("B5").Offset(1, 0).Select
        i = 0
        j = 0
 
        Do While j < 2 'va jusqu'à 2 lignes vides après la dernière ligne visible filtrée
            Do While ActiveCell.EntireRow.Hidden = True 'teste si la ligne est visible
                ActiveCell.Offset(1, 0).Select
            Loop
            i = i + 1
            If ActiveCell = "" Then
                j = j + 1
            Else
                Reference(i) = ActiveCell.Value 'enregistre les valeurs, pour chaque ligne visible, dans des tables définies
                Defaut(i) = ActiveCell.Offset(0, 1).Value
                Action(i) = ActiveCell.Offset(0, 3).Value
                Cible(i) = ActiveCell.Offset(0, 6).Value
            End If
        ActiveCell.Offset(1, 0).Select
        Loop
 
        Sujet = "[CRIME] Rappel du suivi d'action(s)"
 
        Destinataires(0) = Range("G" & plage.Row).Value
        ccDestinataires(1) = "toto@tata.com"
        ccDestinataires(2) = "toto@tata.com"
 
        Set Session = CreateObject("Notes.NotesSession")
        UserName = Session.UserName
        MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
        Set BaseMail = Session.GETDATABASE("", MailDbName)
        If Not BaseMail.IsOpen Then BaseMail.OpenMail
 
        ' Création du message
            Set LeMail = BaseMail.CreateDocument
            Call LeMail.AppendItemValue("Form", "Memo")
            Call LeMail.AppendItemValue("sendTo", Destinataires)
            Call LeMail.AppendItemValue("CopyTo", ccDestinataires)
            Call LeMail.AppendItemValue("Subject", Sujet)
            LeMail.SaveMessageOnSend = True
            Set body = LeMail.CreateRichTextItem("Body")
'-----------------------------------------------------------------------------------------------------
        ' Corps du message
            Call body.AppendText("Bonjour,")
            Call body.AddNewLine(2)
            Call body.AppendText("Voici ci-dessous les actions en cours qui vous sont affectées :")
            Call body.AddNewLine(2)
            ' Création du tableau récapitulatif
                nbcol = 4 ' Est le nombre total de colonnes
                nbrow = plage.Count ' Est le nombre total de lignes visibles(donc nb total d'actions)
 
                ' Definition des colonnes et en-têtes
                    sHeaders(0) = "Référence"
                    Set rtpsCols(0) = LeMail.CreateRichTextParagraphStyle
                    rtpsCols(0).Alignment = 0
                    rtpsCols(0).Firstlineleftmargin = 0
                    rtpsCols(0).LeftMargin = 0
                    rtpsCols(0).RightMargin = RULER_ONE_CENTIMETER * 2.7  '3.5
 
                    sHeaders(1) = "Défaut"
                    Set rtpsCols(1) = LeMail.CreateRichTextParagraphStyle
                    rtpsCols(1).Alignment = 0
                    rtpsCols(1).Firstlineleftmargin = 0
                    rtpsCols(1).LeftMargin = 0
                    rtpsCols(1).RightMargin = RULER_ONE_CENTIMETER * 2.1 '4.00
 
                    sHeaders(2) = "Action"
                    Set rtpsCols(2) = LeMail.CreateRichTextParagraphStyle
                    rtpsCols(2).Alignment = 0
                    rtpsCols(2).Firstlineleftmargin = 0
                    rtpsCols(2).LeftMargin = 0
                    rtpsCols(2).RightMargin = RULER_ONE_CENTIMETER * 0.7 '0.9
 
                    sHeaders(3) = "Date Cible"
                    Set rtpsCols(3) = LeMail.CreateRichTextParagraphStyle
                    rtpsCols(3).Alignment = 0
                    rtpsCols(3).Firstlineleftmargin = 0
                    rtpsCols(3).LeftMargin = 0
                    rtpsCols(3).RightMargin = RULER_ONE_CENTIMETER * largTAGIS '5.58
            '-------------------------------------------------------------------------
                ' Définition des élément visuels du tableau
                Set rtsStyleBarCode = LeMail.CreateRichTextStyle
                    rtsStyleBarCode.FontSize = 17
                    rtesStyleBarCode.NotesFont = body.GetNotesFont("3 of 9 Barcode", True)
 
                Set rtsTableHeader = LeMail.CreateRichTextStyle
                    rtsTableHeader.FontSize = 9
                    rtsTableHeader.Bold = True 'en-tête en gras
                    rtsTableHeader.NotesFont = body.GetNotesFont("Sans Serif par défaut", True)
 
                Set rtsTableRow = LeMail.CreateRichTextStyle
                    rtsTableRow.FontSize = 6
                    rtsTableRow.Bold = False
                    rtseTableRow.NotesFont = body.GetNotesFont("Small Fonts", True)
 
                Set rtpsColsTAGIS(0) = LeMail.CreateRichTextParagraphStyle
                    rtpsColsTAGIS(0).Alignment = 0
                    rtpsColsTAGIS(0).Firstlineleftmargin = 0
                    rtpsColsTAGIS(0).LeftMargin = 0
                    rtpsColsTAGIS(0).RightMargin = RULER_ONE_CENTIMETER * 19.41 '3.5
            '-------------------------------------------------------------------------
                Set rtnav = body.CreateNavigator 'création de la variable de navigation dans le tableau
                Call body.AppendTable(nbrow, nbcol, "", 350, rtpsCols) 'créé un tableau de nbrow lignes et nbcol colonnes
 
                ' Renseigne les en-têtes
                Call body.AppendStyle(rtsTableHeader)
                Call rtnav.FindFirstElement(RTELEM_TYPE_TABLECELL)
                For iCol = 1 To nbcol Step 1
                    Call body.BeginInsert(rtnav)
                    Call body.AppendText(sHeaders(iCol - 1))
                    Call body.EndInsert
                    Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
                Next
 
                ' Renseigne les cellules du tableau en fonction des lignes et colonnes
                Call body.AppendStyle(rtsTableRow)
                Call rtnav.FindFirstElement(RTELEM_TYPE_TABLECELL)
                For iRow = 1 To nbrow Step 1
                    For iCol = 1 To nbcol Step 1
                        Call body.BeginInsert(rtnav)
                        If iCol = 1 Then Call body.AppendText(Reference(iRow))
                        If iCol = 2 Then Call body.AppendText(Defaut(iRow))
                        If iCol = 3 Then Call body.AppendText(Action(iRow))
                        If iCol = 4 Then Call body.AppendText(Cible(iRow))
                        Call body.EndIsert
                        Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
                    Next
                Next
                Call doc.Save(True, False)
                Call ws.ViewRefresh
'-----------------------------------------------------------------------------------------------------
        ' Envoi du mail réalisé
            LeMail.SaveMessageOnSend = True
            LeMail.PostedDate = Now()
            LeMail.Send 0
 
        ' On vide la database pour recommencer un mail tout neuf pour le prochain destinataire
            Set BaseMail = Nothing
            Set LeMail = Nothing
            Set Session = Nothing
            Set body = Nothing
            Set rtpsCols(3) = Nothing
            Set rtpsColsTAGIS(0) = Nothing
            Set rtsStyleBarCode = Nothing
            Set rtsTableHeader = Nothing
            Set rtsTableRow = Nothing
            Set rtnav = Nothing
    Next
End With
 
End Sub
Le code plante à la ligne 107 et probablement aux lignes 114, 121, 128, 135, 139, 144 et 149 lorsque j'utilise "LeMail". Aurai-tu une idée de comment déclarer LeMail?

Merci !