XL 2013 Problème avec macro « Bouton suiveur »

Christophe78129

XLDnaute Nouveau
Bonjour,
Après recherche, j’ai trouvé une macro qui permet de « figer » un contrôle X, mais après plusieurs essais je n’arrive pas à l’adapter à mon cas. Dans la macro le bouton reste toujours au milieu de la feuille.
Pour mon cas, je voudrai que le bouton soit au 2/3 de l’écran.
Si quelqu’un a une solution à me proposer.

Merci d’avance
VB:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim Haut_Haut As Long, Haut_Info As Long, Haut_Bas As Long
 
    With ActiveWindow.ActivePane.VisibleRange
        Haut_B1 = .Top + (Height / 2)
    End With

    With Haut_de_page
        .Top = Haut_B1 - (.Height / 2)
    End With

End Sub
 
Solution
bonsoir
un exemple avec un bouton
VB:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim usable As Range
    Set usable = ActiveWindow.ActivePane.VisibleRange
    'les 2 tiers
    CommandButton1.Left = usable.Left + (usable.Width - CommandButton1.Width) / 3 * 2
    CommandButton1.Top = usable.Top + (usable.Height - CommandButton1.Height) / 3 * 2
End Sub

Dranreb

XLDnaute Barbatruc
Bonsoir.
Vous avez déclaré 3 variables qui ne servent à rien, et en utilisez 2 non déclarées.
Mettez Option Explicit en tête du module pour qu'il ne tente plus d'exécution si des variables ne sont pas déclarées.
Cela dit je ne comprend pas pourquoi il se retrouve au milieu de l'écran: il devrait être collé contre la limite supérieure de la fenêtre active, puisque son .Top ne peut pas être négatif.
 
Dernière édition:

patricktoulon

XLDnaute Barbatruc
bonsoir
un exemple avec un bouton
VB:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim usable As Range
    Set usable = ActiveWindow.ActivePane.VisibleRange
    'les 2 tiers
    CommandButton1.Left = usable.Left + (usable.Width - CommandButton1.Width) / 3 * 2
    CommandButton1.Top = usable.Top + (usable.Height - CommandButton1.Height) / 3 * 2
End Sub
 

patricktoulon

XLDnaute Barbatruc
re
bonjour
pour les 3 boutons
VB:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim usable As Range
    Set usable = ActiveWindow.ActivePane.VisibleRange
    'les 2 tiers
    CommandButton2.Left = usable.Left + (usable.Width - CommandButton2.Width) / 3 * 2
    CommandButton2.Top = usable.Top + (usable.Height - (CommandButton2.Height / 2)) / 2 '(/2= à l'axe)(/3*2 = axe a 2 tiers)
    CommandButton1.Left = CommandButton2.Left
    CommandButton1.Top = CommandButton2.Top - CommandButton1.Height - 5
    CommandButton3.Left = CommandButton2.Left
    CommandButton3.Top = CommandButton2.Top + CommandButton3.Height + 5
End Sub
 

Discussions similaires

Statistiques des forums

Discussions
312 196
Messages
2 086 101
Membres
103 116
dernier inscrit
kutobi87