Une mini feinte (a developper si tu veux) :
-> je cache la fenetre (probleme : il n'y a plus de bouton dans la barre de navigation)
> comme cela bloque la visibilite des autres Xcel, il faut une astuce, pour comprendre comment ca marche, j'ai donc utilise un Class Module qui se declenche a chaque ouverture de fichier : si le fichier ouvert est le mien, je le ferme et le rouvre ailleurs / sinon, je ferme l'autre et le rouvre ailleurs)
-> mais ce n'est pas parfait non plus (vous verrez dans les commentaires, il y a encore du travail!)
J'ai donc :
Dans le workbook directement :
Private Sub Workbook_Open()
Call StartAutomatic
End Sub
Dans un module :
Private p_evtEvents As XlEvents
Public ThisOneIsTheGoodOne As Workbook
Sub StartAutomatic()
Set ThisOneIsTheGoodOne = ThisWorkbook
Set p_evtEvents = New XlEvents
Application.Visible = False
'The UserForm ShowModal Property Should be set to False
UserForm1.Show
End Sub
Sub test()
Application.Visible = True
Debug.Print Application.Workbooks("PERSONAL.XLS").FullName
End Sub
Dans un class module nomme "XlEvents"
Private WithEvents XlApp As Excel.Application
Private Sub Class_Initialize()
Set XlApp = Application
End Sub
Private Sub XlApp_WorkbookOpen(ByVal Wb As Workbook)
'opening a Workbook put the app visible
Application.Visible = False
For Each mywbk In Application.Workbooks
If Not Wb Is ThisOneIsTheGoodOne And Not Wb.Name = "PERSONAL.XLS" Then
wbname = ThisOneIsTheGoodOne.FullName
aa = Shell(Chr(34) & Application.Path & "\excel.exe" & Chr(34) _
& " " & Chr(34) & wbname & Chr(34) _
, vbMaximizedFocus _
)
ThisOneIsTheGoodOne.Close
Exit Sub
End If
Next
wbname =Wb.Name
'This part could be greatly improved : in case we find another window
'then instead of doing a simple shell (new window each time),
'we could try to locate the other window and open it there !!!
aa = Shell(Chr(34) & Application.Path & "\excel.exe" & Chr(34) _
& " " & Chr(34) & wbname & Chr(34) _
, vbMaximizedFocus _
)
Wb.Close savechanges:=False
End Sub