Bonjour,
souhaitant adapter ce code à mon fichier excel afin d'envoyer des mails à une liste de personnes contenue dans un tableau, je rencontre un problème de <gras>type code 9 l'indice n'appartient pas à la sélection</gras>. Après avoir cherché sur différents forums et essayé les différentes solutions proposées ( changement de nom du tableau, remplacement de Worksheets () par sheets ()...) l'erreur persiste toujours. Je tiens à confirmer que l'onglet contenant le tableau s'appelle "MAIL" et la sélection du tableau "Salaries_Suivi".
C'est assez urgent je dois terminer ce fichier avant ma soutenance fin août.
Ci-dessous, le code. L'erreur apparait au niveau de la ligne en gras.
Sub Mailing()
Dim OutlookApp As Object
Dim OutlookMail As Object
Dim Wb1 As Workbook
Dim Ws1 As Worksheet
Dim cell As Range
Dim Rg As Range
Dim tableauMailer As ListObject
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
If Not LancementMailing Then Exit Sub
Set Wb1 = ThisWorkbook
Set Ws1 = Wb1.Worksheets("MAIL")
Set OutlookApp = CreateObject("Outlook.Application")
Set tableauMailer = Ws1.ListObjects("Salaries_Suivi")
For Each cell In tableauMailer.ListColumns(1).DataBodyRange.SpecialCells(xlCellTypeVisible)
Set Rg = Range(Cells(cell.Row, 1), Cells(cell.Row, tableauMailer.ListColumns.Count))
TexteHtml = "corps de texte"
If cell.Offset(0, 2).Value Like "?*@?*.?*" And _
Application.WorksheetFunction.CountA(Rg) > 0 Then
Set OutlookMail = OutlookApp.CreateItem(0)
With OutlookMail
.To = cell.Offset(0, 2).Value
.Subject = cell.Offset(0, 4).Value
.htmlBody = cell.Offset(0, 5).Value
.Send
End With
Set OutlookMail = Nothing
End If
Next cell
Set OutlookMail = Nothing
Set Ws1 = Nothing
Set Wb1 = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
En attendant votre aide.
Merci par avance