作为VBA新手,我正在尝试向我的工作表添加自定义滚动条。通过自定义,我的意思是我可以使用Userform来确定滚动条的最小值,最大值和小变化,我在其中询问想要的值。到目前为止,我已经存储在以下公共变量的值: screen of the UserformVBA自定义用户窗体变量的滚动条
Option Explicit
Public A As Integer
Public B As Integer
Public C As Integer
Private Sub Valider_Click()
If IsNumeric(TextBox1.Value) Then
A = TextBox1.Value
Unload Me
Else
MsgBox "Valeur mimimale incorrecte"
End If
If IsNumeric(TextBox2.Value) Then
B = TextBox2.Value
Unload Me
Else
MsgBox "Valeur maximale incorrecte"
End If
If IsNumeric(TextBox3.Value) Then
C = TextBox3.Value
Unload Me
Else
MsgBox "Pas incorrect"
End If
MsgBox A & " " & B & " " & C
End Sub
,我只是重新分配“.Min”,“最大”和值“.SmallChange。”用A,B和C在用Excel给出的defaut滚动代码:
Sub curseur()
ActiveSheet.ScrollBars.Add(180, 45.75, 119.25, 13.5).Select
With Selection
.Value = 0
.Min = A
.Max = B
.SmallChange = C
.LargeChange = 10
.LinkedCell = "$G$4"
.Display3DShading = True
End With
Range("F4").Select
ActiveCell.FormulaR1C1 = "=RC[1]/100"
Range("G4").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
End With
End Sub
所以我有3个文本框和一个命令按钮( “验证者”)。基本上我的想法是用预先设定的值(min,max,...)完成这3个盒子,并将它们存储在公共变量中。目前,我只是使用F5从developper选项卡运行我的代码。
我第一次运行userform。一旦文本框完成并按下CommandButton,MessageBox就会返回变量A,B和C中包含的值。然后我想用这些来“定义”我的滚动条。当我按F5时,滚动条显示自己(见截图),但如果我去属性所有值设置为零。似乎我没有调用变量A,B,C正确的方式:scrollbar properties
在此先感谢您的帮助。
究竟发生了什么以及缺少什么?你有一个包含多个文本框的表单吗?因为你在第一次检查后卸货。你的msgbox说什么?你如何以及何时调用你的代码?请添加一些细节以帮助我们提供帮助。我不知道你是如何转发你的滚动条的参数... – Jochen
我编辑我的帖子,添加2个截图和更详细的解释。它有帮助吗? (我很抱歉,因为我是新手,我不确定你需要哪些信息,但这几乎都是我的代码)。感谢您的帮助btw! – beckq