savoir si une listbox a une scrollbar verticale ou pas

patricktoulon

XLDnaute Barbatruc
bonjour a tous
voici une petite astuce pour les listbox dans userform que j'ai mis a jour pour les listbox sur feuille
cet fonction renvoie un blooleen true/false selon si la listbox a la scrollbar verticale ou pas

fonction à mettre dans un module
VB:
Option Explicit
Function HasVerticalScrollBar(Ctrl)
    Dim q$, Fsz&
    Fsz = Ctrl.Font.Size
    q = Application.Rept("A" & vbCrLf, Ctrl.ListCount): q = Left(q, Len(q) - 2)

    If TypeOf Ctrl.Parent Is UserForm Then
        With Ctrl.Parent.Controls.Add("forms.Label.1", "X3Xy")
            .Height = Ctrl.Parent.Height: .Caption = q: .Font.Size = Ctrl.Font.Size: .Font.Name = Ctrl.Font.Name
            .Font.Bold = Ctrl.Font.Bold: .BorderStyle = Ctrl.BorderStyle: .AutoSize = True
            HasVerticalScrollBar = .Height > Ctrl.Height
            Ctrl.Parent.Controls.Remove .Name
        End With
    Else
        With ActiveSheet.Shapes.AddLabel(msoTextOrientationHorizontal, 10, 10, 10, 10)
            With .TextFrame: .Characters.Text = q: .MarginLeft = 0: .MarginRight = 0: .MarginTop = 0: .MarginBottom = 0: End With
            With .Parent.DrawingObjects(.Name)
                .Font.Size = Fsz: .Font.Name = Ctrl.Object.Font.Name: .Font.Color = RGB(0, 210, 255)
                .HorizontalAlignment = xlHAlignCenter: .VerticalAlignment = xlVAlignCenter
            End With
            HasVerticalScrollBar = .Height > Ctrl.Height
            .Delete
        End With
    End If
End Function

exemple d'utilisation
VB:
MsgBox HasVerticalScrollBar(ListBox1)
 

Statistiques des forums

Discussions
312 215
Messages
2 086 326
Membres
103 180
dernier inscrit
Vcr