Variable i ne fonctionne pas pour changer la sélection d'onglets

Bonjour,

Sur mon code le changement d'onglet avec la variable i ne fonctionne pas

Je souhaite sélectionner un onglet ou le nom se situe en G1 sur Sheets("BDD") voir mon code.

une fois le mail envoyé on passe à G2 avec le (& i).

tout le reste du code est ok

Sub testEmail()
Dim olApp As Outlook.Application
Set olApp = CreateObject("outlook.application")
Dim wb As Workbook
Dim filename As String
Dim olMail As Outlook.MailItem
Dim i As Integer: i = 1
Set wb = ActiveWorkbook
With wb

   Do

        filename = .Path & "\" & .Sheets(Sheets("BDD").Range("G" & i).Text).Name & ".pdf"
        .Sheets(Sheets("BDD").Range("G" & i).Text).ExportAsFixedFormat xlTypePDF, filename, , , False
        With .Sheets(Sheets("BDD").Range("G" & i).Text)
           With olApp.CreateItem(olMailItem)
                .To = wb.Sheets("BDD").Range("H" & i).Value '.Recipients.Add Sheets("BDD").Range("H" & i).Value
                .CC = wb.Sheets("BDD").Range("I" & i).Value
                .Subject = "SITUATION des SILLONS"
                .Body = MyBody
                .Attachments.Add filename
                .Display
                '.Send
            End With

        End With

    i = i + 1
    Loop While filename = .Path & "\" & .Sheets(Sheets("BDD").Range("G" & i).Text).Name & ".pdf"
    .Sheets(1).ExportAsFixedFormat xlTypePDF, filename, , , False
End With

End Sub

Function MyBody()
temp = "Bonjour," & vbLf & vbLf
temp = temp & "Vous trouverez ci joint les sillons obtenus et les commandes en cours." & vbLf & vbLf
temp = temp & "Cordialement" & vbLf & vbLf & vbLf
temp = temp & "Adrien LOBEL"
MyBody = temp
End Function

je sollicite votre aide.

Bonjour,

Sans fichier pour tester ...

Un pas-à-pas à l'aide de F8 et F9 permettrait de trouver rapidement ...

.Sheets(1) ou .Sheets(i) ?

ric

Rechercher des sujets similaires à "variable fonctionne pas changer selection onglets"