SmartFAQ is developed by The SmartFactory (http://www.smartfactory.ca), a division of InBox Solutions (http://www.inboxsolutions.net)

[VBA] Comment tester si un onglet existe déjà ?

Q&R publiée par MyDearFriend! le 26-03-2008 (20949 Lectures)

Voici une fonction personnalisée pour réaliser ce test simplement :

DANS UN MODULE DE CODE STANDARD
Function FeuilExiste(F As String) As Boolean
'myDearFriend!  -  www.mdf-xlpages.com
    On Error Resume Next
    FeuilExiste = Not Sheets(F) Is Nothing
End Function


Exemple d'utilisation :

Sub Test() 
Dim Feuil As String

    Feuil = "MaFeuille"
    
    If FeuilExiste(Feuil) Then
        MsgBox "L'onglet " & Feuil & " existe déjà dans le classeur actif."
    Else
        MsgBox "L'onglet " & Feuil & " n'existe pas dans le classeur actif."
    End If
End Sub

  Imprimer la Q&R Envoyer la Q&R