Option Explicit
Private Function FeuilleExiste(sNomFeuille As String, Optional Wkb As Workbook = Nothing) As Boolean
Dim Ws As Worksheet
FeuilleExiste = False
If Wkb Is Nothing Then
Set Wkb = ThisWorkbook
End If
For Each Ws In Wkb.Worksheets
If Ws.Name = sNomFeuille Then
FeuilleExiste = True
Set Wkb = Nothing
Exit For
End If
Next Ws
Set Wkb = Nothing
End Function
Merci.Salut, vite fait, à tester/adapter à ton contexte
VB:Option Explicit Function FeuilleExiste(sNomFeuille As String, Optional Wkb As Workbook = Nothing) As Boolean Dim Ws As Worksheet FeuilleExiste = False If Wkb Is Nothing Then Set Wkb = ThisWorkbook End If For Each Ws In Wkb.Worksheets If Ws.Name = sNomFeuille Then FeuilleExiste = True Set Wkb = Nothing Exit For End If Next Ws Set Wkb = Nothing End Function
Optional Wkb As Workbook = Nothing
Sub Tst()
Dim NomFeuille As String
Dim Wkb As Workbook
On Error Resume Next
NomFeuille = "Liste"
Set Wkb = Workbooks("Classeur2.xlsm")
If FeuilleExiste(NomFeuille, Wkb) Then
MsgBox NomFeuille & " existe"
Else
MsgBox NomFeuille & " n'existe pas"
End If
Set Wkb = Nothing
End Sub
Merci infiniment !!Re, et ceci est là pour quoi ?Code:Optional Wkb As Workbook = Nothing
Arrête de fonctionner par psittacisme, et de recopier un code qui en plus a été modifié !
VB:Sub Tst() Dim NomFeuille As String Dim Wkb As Workbook On Error Resume Next NomFeuille = "Liste" Set Wkb = Workbooks("Classeur2.xlsm") If FeuilleExiste(NomFeuille, Wkb) Then MsgBox NomFeuille & " existe" Else MsgBox NomFeuille & " n'existe pas" End If Set Wkb = Nothing End Sub