Cette rubrique sera alimentée j'espère régulièrement. Voici pour débuter.
_____________________________________________________________
Pour tous les codes à venir il faut
1 - Ouvrir VBE (Alt + F11)
2 - Se placer sur le projet VBA du classeur
C'est du style : VBAProject(Classeur1)
Si la fenêtre des projets n'est pas visible, il suffit de cliquer sur le menu Affichage > Explorateur de projets.
3 - Dans les exemples donnés, il y aura juste un affichage d'une msgbox
_____________________________________________________________
1 - Evènements du classeur
Le code doit se trouver dans le "ThisWorkbook"
1.1 - A l'ouverture du classeur
1.2 - A la fermeture du classeur
____________________________________________________________
2 - Evènements d'une feuille
Le code doit se trouver dans le code de la feuille concernée
2.1 - Quand on clique sur la cellule "A1" uniquement
2.2 - Quand on clique n'importe où dans la colonne "A" uniquement
2.3 - Quand on clique n'importe où dans les colonne "A" à "E" uniquement
2.4 - Quand on clique n'importe où dans la Plage de "A1 à A10" uniquement
2.5 - Quand on clique n'importe où dans plusieurs plages non-adjacentes
2.6 - Quand on clique n'importe où dans plusieurs colonnes non-contigues
2.7 - Quand on clique n'importe où dans la ligne 1
2.8 - Quand on clique n'importe où entre les lignes 1 et 3
2.9 - Quand on clique n'importe où dans dans les lignes 1 ou 3 uniquement (pas la 2)
_____________________________________________________________
Merci à Brigitte, Skoobi et Thierry pour leurs participations
_____________________________________________________________
Pour tous les codes à venir il faut
1 - Ouvrir VBE (Alt + F11)
2 - Se placer sur le projet VBA du classeur
C'est du style : VBAProject(Classeur1)
Si la fenêtre des projets n'est pas visible, il suffit de cliquer sur le menu Affichage > Explorateur de projets.
3 - Dans les exemples donnés, il y aura juste un affichage d'une msgbox
_____________________________________________________________
1 - Evènements du classeur
Le code doit se trouver dans le "ThisWorkbook"
1.1 - A l'ouverture du classeur
Code:
Private Sub Workbook_Open()
MsgBox "Merci d’avoir ouvert ce fichier"
End Sub
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
MsgBox "A BIENTOT, merci d’avoir consulté le fichier"
End Sub
2 - Evènements d'une feuille
Le code doit se trouver dans le code de la feuille concernée
2.1 - Quand on clique sur la cellule "A1" uniquement
Code:
[COLOR=black]Private Sub Worksheet_SelectionChange(ByVal Target As Range)[/COLOR]
[COLOR=black]If Not Application.Intersect(Target, Range("A1")) Is Nothing Then[/COLOR]
[COLOR=black]MsgBox "Click on " & Target.Address[/COLOR]
[COLOR=black]End If[/COLOR]
[COLOR=black]End Sub[/COLOR]
Code:
[COLOR=black]Private Sub Worksheet_SelectionChange(ByVal Target As Range)[/COLOR]
[COLOR=black]If Not Application.Intersect(Target, Range("A:A")) Is Nothing Then[/COLOR]
[COLOR=black]MsgBox "Click on " & Target.Address[/COLOR]
[COLOR=black]End If[/COLOR]
[COLOR=black]End Sub[/COLOR]
Code:
[COLOR=black]Private Sub Worksheet_SelectionChange(ByVal Target As Range)[/COLOR]
[COLOR=black]If Not Application.Intersect(Target, Range("A:E")) Is Nothing Then[/COLOR]
[COLOR=black]MsgBox "Click on " & Target.Address[/COLOR]
[COLOR=black]End If[/COLOR]
[COLOR=black]End Sub[/COLOR]
Code:
[COLOR=black]Private Sub Worksheet_SelectionChange(ByVal Target As Range)[/COLOR]
[COLOR=black]If Not Application.Intersect(Target, Range("A1:A10")) Is Nothing Then[/COLOR]
[COLOR=black]MsgBox "Click on " & Target.Address[/COLOR]
[COLOR=black]End If[/COLOR]
[COLOR=black]End Sub[/COLOR]
Code:
[COLOR=black]Private Sub Worksheet_SelectionChange(ByVal Target As Range)[/COLOR]
[COLOR=black]If Not Application.Intersect(Target, Range("A1:A12, D4:D10, D20, D22, D55, E1:E12")) Is Nothing Then[/COLOR]
[COLOR=black]MsgBox "Click on " & Target.Address[/COLOR]
[COLOR=black]End If[/COLOR]
[COLOR=black]End Sub[/COLOR]
Code:
[COLOR=black]Private Sub Worksheet_SelectionChange(ByVal Target As Range)[/COLOR]
[COLOR=black]If Not Application.Intersect(Target, Range("A:A, C:C, E:E")) Is Nothing Then[/COLOR]
[COLOR=black]MsgBox "Click on " & Target.Address[/COLOR]
[COLOR=black]End If[/COLOR]
[COLOR=black]End Sub [/COLOR]
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Target, Rows(1)) Is Nothing Then
MsgBox "Click on " & Target.Address
End If
End Sub
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Target, Range(Rows(1), Rows(3))) Is Nothing Then
MsgBox "Click on " & Target.Address
End If
End Sub
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Target, Range(Rows(1), Rows(3))) Is Nothing Then
If Application.Intersect(Target, Rows(2)) Is Nothing Then
MsgBox "Click on " & Target.Address
End If
End If
End Sub
Merci à Brigitte, Skoobi et Thierry pour leurs participations
Dernière modification par un modérateur: