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 81 82 83 84 85 86 87 88 89 90 91
| Option Explicit
Dim ws As Worksheet
Dim btn As Button
Dim Continuer As Boolean
Dim NextCell As Range
Private Sub btnEst_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
MoveBtn 0, 1
End Sub
Private Sub btnEst_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Continuer = False
End Sub
Private Sub btnNord_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
MoveBtn -1, 0
End Sub
Private Sub btnNord_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Continuer = False
End Sub
Private Sub btnOuest_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
MoveBtn 0, -1
End Sub
Private Sub btnOuest_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Continuer = False
End Sub
Private Sub btnSud_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
MoveBtn 1, 0
End Sub
Private Sub btnSud_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Continuer = False
End Sub
Private Sub btnNouveau_Click()
Dim n As Integer
Set ws = ActiveSheet
Set btn = ws.Buttons.Add(Application.Width / 2 - 50, Application.Height / 2 - 15, 100, 30)
n = ws.Shapes.Count
With btn
.Name = "CB_baes" & n
.Caption = "baes " & n
.OnAction = "BtnBaes" & n
End With
btn.Select
End Sub
Private Function BoutonActif() As String
Dim shp As Shape
If Selection Is Nothing Then
BoutonActif = ""
Else
If TypeName(Selection) = "Shape" Then '--- vérifie si l'objet sélectionné est une forme
If shp.Type = msoFormControl Then '--- vérifie si la forme est un bouton
If shp.FormControlType = xlButtonControl Then
BoutonActif = shp.Name
End If
Else
BoutonActif = ""
End If
ElseIf TypeName(Selection) = "Button" Then
BoutonActif = Selection.Name
Else
BoutonActif = ""
End If
End If
End Function
Private Sub MoveBtn(dX As Integer, dY As Integer)
'--- tant que l'on appuie sur le bouton du PAD, le bouton de la feuille est déplacé dans le sens sélectionné
Set ws = ActiveSheet
If BoutonActif <> "" Then
Continuer = True
Set btn = Selection
Debug.Print "btn: " & btn.Name
Do While Continuer
With btn
Set NextCell = ws.Cells(.topLeftCell.Row + dX, .topLeftCell.Column + dY) '--- cellule suivante
.Top = NextCell.Top
.Left = NextCell.Left
End With
Application.Wait Now + TimeValue("00:00:01") '--- attend 1 seconde
DoEvents '--- pour permettre à l'événement MouseUp d'être capté (sinon boucle indéfiniment)
Loop
End If
End Sub |
Partager