VBA/Excel/Access/Word/Forms/SpinButton

Материал из VB Эксперт
Перейти к: навигация, поиск

Assign value from a TextBox to a Spinner

 
  Private Sub TextBox1_Change()
      Dim NewVal As Integer
      NewVal = Val(TextBox1.Text)
      If NewVal >= SpinButton1.Min And _
          NewVal <= SpinButton1.Max Then _
          SpinButton1.Value = NewVal
  End Sub



Set Spinner value to a TextBox

 
  Private Sub SpinButton1_Change()
      TextBox1.Text = SpinButton1.Value
  End Sub



Set the SpinButton Min/Max and current value

 
Private Sub UserForm_Initialize()
    With SpinButton1
        .Min = 1
        .Max = 100
        Label1.Caption = "Specify a value between " & .Min & " and " & .Max & ":"
"       Initialize Spinner
        .Value = 1
"       Initialize TextBox
        TextBox1.Text = .Value
    End With
End Sub



Spin up event procedure for spin button

 
     Private Sub SpinButton1_SpinUp()
         With Range("B4")
             "Increase value in B4 by .05%. Stop at 1%
             .Value = WorksheetFunction.Min(0.01, .Value + 0.0005)
         End With
     End Sub



The spin button control uses the SpinDown and SpinUp events to decrease and increase the value in cell B4

 
"Spin down event procedure for spin button
     Private Sub SpinButton1_SpinDown()
         With Range("B4")
             "Decrease value in B4 by .05%. Stop at 0%
             .Value = WorksheetFunction.Max(0, .Value - 0.0005)
         End With
     End Sub