Я не могу найти ответ на мою проблему. Я создаю пользовательскую форму динамически. Количество элементов управления зависит от списка людей. Если народов мало, там мало контроля. Но когда у меня слишком много элементов управления для размера моей пользовательской формы, я динамически создаю полосу прокрутки. Мне бы хотелось, чтобы эта полоса прокрутки могла двигаться с помощью колесика мыши.
Вот как я могу определить, добавляю ли я полосу прокрутки в мою форму пользователя. Это делается с помощью кода другой пользовательской формы. Как включить управление колесом мыши на полосе прокрутки? Я довольно новичок в VBA, поэтому мне понадобится подробный ответ, пожалуйста.
Спасибо за вашу помощь.
(rosterfill - это пользовательская форма, которую я хочу, чтобы колесико мыши перемещалось с помощью колесика мыши)
If Page2.OptionButton1.Value = True And Shift.OptionButton1.Value = True Then
shi = 1
rosterfill.Label1.Caption = dpt
rosterfill.Label2.Caption = "Shift " & shi
rosterfill.Label3.Caption = jour
rosterfill.Label4.Caption = "Hours worked"
rosterfill.Label5.Caption = "Any comment"
rosterfill.Label4.Left = 700
rosterfill.Label4.Width = 50
rosterfill.Label4.Height = 24
rosterfill.Label5.Left = 800
rosterfill.Label5.Width = 100
rosterfill.Label5.Height = 24
'open roster and add the names
Workbooks.Open (pathroot & "\" & dpt & "\Roster.xlsx")
Worksheets("Shift " & shi).Activate
lastrowd = Cells(Rows.Count, 1).End(xlUp).Row
topini = 18
initop = 18
For i = 6 To lastrowd
Set thelabel = rosterfill.Controls.add("Forms.TextBox.1", "label" & i, True)
With thelabel
.Value = Cells(i, 1).Value 'name of the person
.Left = 6
.Width = 234
.Top = topini + 30
.Locked = True
.Height = 24
End With
Set theframe = rosterfill.Controls.add("Forms.Frame.1", "frame" & i, True)
With theframe
.Top = initop + 30
.Width = 100
.Left = 246
.Height = 24
Set here = .Controls.add("forms.OptionButton.1", "here" & i, True)
With here
.Height = 18
.Left = 5
.Width = 108
.Caption = "here"
End With
Set absent = .Controls.add("forms.OptionButton.1", "absent" & i, True)
With absent
.Height = 18
.Left = 50
.Width = 108
.Caption = "absent"
End With
End With
Set theframe2 = rosterfill.Controls.add("Forms.Frame.1", "frame2" & i, False)
With theframe2
.Top = initop + 30
.Width = 350
.Left = 350
.Height = 24
Set abs1 = .Controls.add("forms.OptionButton.1", "abs1" & i, True)
With abs1
.Height = 18
.Left = 5
.Width = 108
.Caption = "PTO"
End With
Set abs2 = .Controls.add("forms.OptionButton.1", "abs2" & i, True)
With abs2
.Height = 18
.Left = 35
.Width = 108
.Caption = "UPTO"
End With
Set abs3 = .Controls.add("forms.OptionButton.1", "abs3" & i, True)
With abs3
.Height = 18
.Left = 75
.Width = 108
.Caption = "MED"
End With
Set abs4 = .Controls.add("forms.OptionButton.1", "abs4" & i, True)
With abs4
.Height = 18
.Left = 110
.Width = 108
.Caption = "ANCI"
End With
Set abs11 = .Controls.add("forms.OptionButton.1", "abs11" & i, True)
With abs11
.Height = 18
.Left = 150
.Width = 108
.Caption = "ACI"
End With
Set abs5 = .Controls.add("forms.OptionButton.1", "abs5" & i, True)
With abs5
.Height = 18
.Left = 185
.Width = 108
.Caption = "FMLA"
End With
Set abs6 = .Controls.add("forms.OptionButton.1", "abs6" & i, True)
With abs6
.Height = 18
.Left = 225
.Width = 108
.Caption = "AE"
End With
Set abs7 = .Controls.add("forms.OptionButton.1", "abs7" & i, True)
With abs7
.Height = 18
.Left = 255
.Width = 108
.Caption = "S"
End With
Set abs8 = .Controls.add("forms.OptionButton.1", "abs8" & i, True)
With abs8
.Height = 18
.Left = 280
.Width = 108
.Caption = "BRV"
End With
Set abs9 = .Controls.add("forms.OptionButton.1", "abs9" & i, True)
With abs9
.Height = 18
.Left = 310
.Width = 108
.Caption = "JD"
End With
Set abs10 = .Controls.add("forms.OptionButton.1", "abs10" & i, False)
With abs10
.Height = 18
.Left = 400
.Width = 108
.Caption = "Q or T"
.Locked = True
End With
End With
Set hours = rosterfill.Controls.add("forms.TextBox.1", "hours" & i, False)
With hours
.Left = 700
.Width = 50
.Top = topini + 30
.Height = 24
End With
Set Comment = rosterfill.Controls.add("forms.TextBox.1", "comment" & i, False)
With Comment
.Left = 755
.Width = 100
.Top = topini + 30
.Height = 24
End With
Set theframe3 = rosterfill.Controls.add("Forms.Frame.1", "frame3" & i, False)
With theframe3
.Top = initop + 30
.Width = 350
.Left = 350
.Height = 24
Set here1 = .Controls.add("forms.OptionButton.1", "h1" & i, True)
With here1
.Height = 18
.Left = 5
.Width = 108
.Caption = "LE"
End With
Set here2 = .Controls.add("forms.OptionButton.1", "h2" & i, True)
With here2
.Height = 18
.Left = 50
.Width = 108
.Caption = "AL"
End With
Set here3 = .Controls.add("forms.OptionButton.1", "h3" & i, True)
With here3
.Height = 18
.Left = 95
.Width = 108
.Caption = "Entire Shift"
End With
End With
topini = topini + 30
initop = initop + 30
Next i
If topini + 100 > 450 Then
rosterfill.Height = 450
rosterfill.CommandButton1.Top = topini + 100 - 60
rosterfill.CommandButton2.Top = topini + 100 - 60
rosterfill.ScrollBars = fmScrollBarsVertical
rosterfill.ScrollHeight = topini + 100
rosterfill.ScrollWidth = 50
rosterfill.ScrollTop = 0
Else
rosterfill.Height = topini + 100
rosterfill.CommandButton1.Top = topini + 100 - 60
rosterfill.CommandButton2.Top = topini + 100 - 60
End If
For i = 6 To lastrowd
If (Range("F" & i).Value = "T" Or Range("F" & i).Value = "Q") Or (Range("G" & i).Value = "T" Or Range("G" & i).Value = "Q") Or (Range("H" & i).Value = "T" Or Range("H" & i).Value = "Q") Or (Range("I" & i).Value = "T" Or Range("I" & i).Value = "Q") Or (Range("J" & i).Value = "T" Or Range("J" & i).Value = "Q") Or (Range("K" & i).Value = "T" Or Range("K" & i).Value = "Q") Then
rosterfill.Controls("absent" & i).Value = True
rosterfill.Controls("here" & i).Value = False
rosterfill.Controls("absent" & i).Locked = True
rosterfill.Controls("here" & i).Locked = True
rosterfill.Controls("abs10" & i).Value = True
rosterfill.Controls("abs10" & i).Locked = True
rosterfill.Controls("abs9" & i).Value = False
rosterfill.Controls("abs9" & i).Locked = True
rosterfill.Controls("abs8" & i).Value = False
rosterfill.Controls("abs8" & i).Locked = True
rosterfill.Controls("abs7" & i).Value = False
rosterfill.Controls("abs7" & i).Locked = True
rosterfill.Controls("abs6" & i).Value = False
rosterfill.Controls("abs6" & i).Locked = True
rosterfill.Controls("abs5" & i).Value = False
rosterfill.Controls("abs5" & i).Locked = True
rosterfill.Controls("abs4" & i).Value = False
rosterfill.Controls("abs4" & i).Locked = True
rosterfill.Controls("abs3" & i).Value = False
rosterfill.Controls("abs3" & i).Locked = True
rosterfill.Controls("abs2" & i).Value = False
rosterfill.Controls("abs2" & i).Locked = True
rosterfill.Controls("abs1" & i).Value = False
rosterfill.Controls("abs1" & i).Locked = True
rosterfill.Controls("frame2" & i).Enabled = False
rosterfill.Controls("comment" & i).Locked = True
rosterfill.Controls("hours" & i).Locked = True
rosterfill.Controls("comment" & i).Enabled = False
rosterfill.Controls("hours" & i).Enabled = False
End If
Next
rosterfill.Show