1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
Private Function EstDansCollection(Coln As Object, Item As String) As Boolean
Dim obj As Object
On Error Resume Next
Set obj = Coln(Item)
EstDansCollection = Not obj Is Nothing
End Function
Private Sub CommandButton1_Click()
Dim Reponse
If EstDansCollection(Workbooks, "Classeur2.xls") = True Then
MsgBox "Le classeur est déjà ouvert !"
Exit Sub
End If
If EstDansCollection(Workbooks, "Classeur2.xls") = False Then
Reponse = MsgBox("Le classeur n'est pas ouvert, voulez-vous l'ouvrir ?", vbInformation + vbYesNo)
If (Reponse = vbNo) Then
Exit Sub
Else
Workbooks.Open ("Classeur2.xls")
End If
End If
End Sub |
Partager