Dim selScl As Long '前回のスクロールバー数値
Private Sub UserForm_Initialize()
Me.ScrollBar1.Min = 1
Me.ScrollBar1.Visible = False
End Sub
Private Sub ScrollBar1_Change()
With Me.TextBox1
If selScl > Me.ScrollBar1.Value Then
.SetFocus
.CurLine = Me.ScrollBar1.Value - 1
ElseIf Me.ScrollBar1.Value > 1 Then
If .SelStart <> .TextLength Then
.SetFocus
.CurLine = Me.ScrollBar1.Value + 6 - 2
End If
End If
End With
selScl = Me.ScrollBar1.Value
Me.Label1.Caption = Me.ScrollBar1.Value
End Sub
Private Sub TextBox1_Change()
With Me.TextBox1
If .LineCount > 6 Then
Me.ScrollBar1.Max = .LineCount - 6 + 1
Me.ScrollBar1.Visible = True
Me.ScrollBar1.Value = .LineCount - 6 + 1
End If
End With
End Sub