1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
Function BookOpen(FichierSource As String) As Boolean
Dim oBk As Workbook
On Error Resume Next
On Error GoTo 0
Set oBk = Workbooks(FichierSource)
If oBk Is Nothing Then
BookOpen = False
Else
BookOpen = True
End If
End Function
Sub DeuxiemeTestSiFichiersSourcesOuverts()
'Procédure pour tester si les fichiers sources sont déjà ouverts
'A appeler dans la procédure TesteSiFichierExiste
Application.ScreenUpdating = False
'Etape 1 : Déclarer le chemin d'accès, le nom du fichier Destinataire,le Workbook et la feuille où sont indiqués les noms des fichiers sources
Chemin = ThisWorkbook.Path & "\"
Set Destinataire = ThisWorkbook
Set ListeDesFichiersSource = Destinataire.Sheets("Nom Fichiers Sources")
'Etape 2 : Tester si les fichiers sources sont ouvert - Si ouverts : message et stop
'Dim FichierSource As string déclaré en variable publique
'Fichier Suivi QP ouvert ?
FichierSource = ListeDesFichiersSource.Cells(2, 2).Value
MsgBox ("Test si " & FichierSource & " est ouvert"), vbOKOnly + vbInformation, "TestSiFichiersSourcesOuverts"
If BookOpen(FichierSource) = True Then '--> Erreur de compilation type d'argument by ref incompatible
MsgBox FichierSource & " is open", vbOKOnly + vbInformation
GoTo Fin
Else
MsgBox FichierSource & " is NOT open", vbOKOnly + vbExclamation
GoTo Suite2
End If
'Fichier OOS Labo ouvert ?
Suite1:
FichierSource = ListeDesFichiersSource.Cells(3, 2).Value
MsgBox ("Test si " & FichierSource & " est ouvert"), vbOKOnly + vbInformation, "TestSiFichiersSourcesOuverts"
If BookOpen(FichierSource) = True Then
MsgBox FichierSource & " is open", vbOKOnly + vbInformation
GoTo Fin
Else
MsgBox FichierSource & " is NOT open", vbOKOnly + vbExclamation
GoTo Suite2
End If
'Fichier Invalides Labo ouvert ?
Suite2:
FichierSource = ListeDesFichiersSource.Cells(4, 2).Value
MsgBox ("Test si " & FichierSource & " est ouvert"), vbOKOnly + vbInformation, "TestSiFichiersSourcesOuverts"
If BookOpen(FichierSource) = True Then
MsgBox FichierSource & " is open", vbOKOnly + vbInformation
GoTo Fin
Else
MsgBox FichierSource & " is NOT open", vbOKOnly + vbExclamation
' appeler la procédure suivante, pour continuer
End If
Application.ScreenUpdating = True
Fin:
End Sub |
Partager