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

[VBA] Comment tester si un classeur est déjà ouvert ?

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

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

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


Exemple d'utilisation :

Sub Test() 
Dim Fichier As String

    Fichier = "MonClasseur.xls"
    
    If FichOuvert(Fichier) Then
        MsgBox "Le fichier " & Fichier & " est ouvert."
    Else
        MsgBox "Le fichier " & Fichier & " n'est pas ouvert."
    End If
End Sub


  Imprimer la Q&R Envoyer la Q&R