j'ai réussi à finir ce que j'avais commencé ce matin
Option Explicit
'Thierry Macro Démo sur Excel-Downloads, February 2003
Dim Verrou As Boolean
Dim Adresse As String
Private Sub ToggleButton1_Click()
If ToggleButton1.Value = True Then
ToggleButton1.Caption = "Phase Insertion"
Verrou = True
Adresse = ActiveCell.Address
Call_UserForm
Else
ToggleButton1.Caption = "Phase Normale"
Userform_Mass_Unloading
Verrou = False
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Verrou = False Then Exit Sub
If Not Application.Intersect(Target, Range("B1:AC12")) Is Nothing Then
Adresse = ActiveCell.Address
Call_UserForm
End If
End Sub
Private Sub Call_UserForm()
Dim d As Date
Dim UserDay As Date
Dim C As Byte
Dim USFname As String
Dim frm
C = ActiveCell.Column
d = Cells(1, C).Value
UserDay = Weekday(d)
USFname = Application.WorksheetFunction.Proper(Format(ActiveSheet.Cells(1, Selection.Cells(1, 1).Column), "dddd"))
For Each frm In Array(Lundi, Mardi, Mercredi, Jeudi, Vendredi, Samedi, Dimanche)
If frm.Name = USFname Then Load frm: frm.Show 0
Next frm
Range(Address).Activate
' Select Case UserDay
' Case 1
' USF_Unload
' Dimanche.Show 0
' Range(Adresse).Select '(un essai pour récupérer le focus sur la cellule)
' Case 2
' USF_Unload
' Lundi.Show 0
' Range(Adresse).Select
' Case 3
' USF_Unload
' Mardi.Show 0
' Range(Adresse).Select
' Case 4
' USF_Unload
' Mercredi.Show 0
' Range(Adresse).Select
' Case 5
' USF_Unload
' Jeudi.Show 0
' Range(Adresse).Select
' Case 6
' USF_Unload
' Vendredi.Show 0
' Range(Adresse).Select
' Case 7
' USF_Unload
' Samedi.Show 0
' Range(Adresse).Activate
' End Select
End Sub
Private Sub USF_Unload()
'J'avais tenté comme çà... Mais non çà ne prend pas !
'Donc méthode classique !!
Unload Lundi
Unload Mardi
Unload Mercredi
Unload Jeudi
Unload Vendredi
Unload Samedi
Unload Dimanche
End Sub
Function FormIsLoaded(MyFormName As String) As Boolean
Dim i As Integer
FormIsLoaded = False
For i = 0 To UserForms.Count - 1
If UserForms(i).Name = MyFormName Then
FormIsLoaded = True
Exit Function ' Quit function once form has been found.
End If
Next i
End Function
Sub test()
On Error Resume Next
For Each frm In Array(Lundi, Mardi, Mercredi, Jeudi, Vendredi, Samedi, Dimanche)
'MsgBox frm.Name
For i = 0 To UserForms.Count - 1
If UserForms(i).Name = frm.Name Then
Set usf = UserForms(i)
Unload usf
End If
Next i
Next frm
End Sub
Sub Userform_Mass_Unloading()
Dim frm
On Error Resume Next
For Each frm In Array(Lundi, Mardi, Mercredi, Jeudi, Vendredi, Samedi, Dimanche)
Unload frm
Next frm
End Sub