Dim nom$, fich$, t# 'mémorise les variables
Private Sub Workbook_Open()
With Application
.OnTime 1, "ThisWorkbook.Ferme"
.Dialogs(xlDialogOpen).Show
If ActiveWorkbook.Name <> Me.Name Then
nom = ActiveWorkbook.Name
fich = ActiveWorkbook.FullName
t = Now + 30 / 86400 'délai 30 secondes
.OnTime 1, "ThisWorkbook.Ferme", , False
.OnTime Now + 1 / 86400, "ThisWorkbook.Ferme"
End If
End With
End Sub
Sub Ferme()
On Error Resume Next
If t Then
If Now < t Then
Application.OnTime Now + 1 / 86400, "ThisWorkbook.Ferme"
If IsError(Workbooks(nom).Name) Then Workbooks.Open fich
Else
t = 0
Workbooks(nom).Close True 'sauvegarde et fermeture
Workbook_Open 'autre ouverture
End If
Else
Me.Saved = True 'évite l'invite
If Workbooks.Count = 1 Then Application.Quit Else Me.Close
End If
End Sub