unload testform
方法loadpicture()
方法进行加载属性窗口里面可以查看
controls(index) controls("name")
可以选定具体的控件Private Sub UserForm_Click()
For i = 0 To Controls.Count - 1
If TypeName(Controls(i)) = "TextBox" Then
MsgBox Controls(i).Value
End If
Next i
End Sub
Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
''''''''''''''code
End Sub
Private Sub UserForm_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
''''''''''''''code
End Sub
Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
''''''''''''''code
End Sub
keydown keypress 都是按键按下,但是一般使用keydown,功能更加强大
Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
End Sub
Private Sub UserForm_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
End Sub
vba一行的代码很长的话可以使用空格加下划线然后enter的方式进行换行
ComboBox1.List(ComboBox1.ListIndex, 2)
Private Sub ComboBox1_Change()
Label1.Caption = "选中项的返回值是:" & ComboBox1.Value
End Sub
Private Sub CommandButton1_Click()
Dim arr
arr = Sheets(1).Range("a8:e15")
ComboBox1.ColumnCount = 5 '设置下拉框显示的列数
ComboBox1.BoundColumn = 3 '设置选中返回的列的数据
ComboBox1.TextColumn = 3 '设置选中下拉框的显示列
ComboBox1.List = arr
End Sub
Private Sub CommandButton2_Click()
ListBox1.RowSource = "Sheet1!A8:E12"
ListBox1.ColumnCount = 5
ListBox1.ColumnHeads = True
ListBox1.BoundColumn = 3
ListBox1.TextColumn = 2
End Sub
Private Sub CommandButton3_Click()
MsgBox ComboBox1.List(ComboBox1.ListIndex, 2)
End Sub
Private Sub CommandButton4_Click()
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
MsgBox ListBox1.List(i, 2)
End If
Next i
End Sub
Private Sub Frame1_Click()
If 男.Value Then sr = "you sex:" & 男.Caption
If 女.Value Then sr = "you sex:" & 女.Caption
If 中.Value Then sr = "you sex:" & 中.Caption
TextBox1.Value = sr
End Sub
Private Sub Frame2_Click()
Dim sr As String
sr = "爱好:"
If 唱歌.Value Then sr = sr & 唱歌.Caption & Chr(10)
If 跳舞.Value Then sr = sr & 跳舞.Caption & Chr(10)
If 篮球.Value Then sr = sr & 篮球.Caption & Chr(10)
TextBox2.Value = sr
End Sub
Private Sub ScrollBar1_Change()
ScrollBar1.SmallChange = 2
ScrollBar1.LargeChange = 10
ScrollBar1.Min = 10
ScrollBar1.Max = 80
TextBox4.Value = ScrollBar1.Value
End Sub
Private Sub SpinButton1_Change()
SpinButton1.SmallChange = 2
TextBox3.Value = SpinButton1.Value
End Sub
vba 中的
Me
变量代表代码所在的对象,如果是工作表代码就代表该工作表,如果是窗体代码就代表窗体
Private Sub Image1_Click()
f = Dir("C:\Users\user\Desktop\*.jpg")
Do
ListBox1.AddItem f
f = Dir
Loop While (Len(f) <> 0)
End Sub
Private Sub ListBox1_Click()
Dim path As String
path = "C:\Users\user\Desktop\" & ListBox1.Value
Image1.Picture = LoadPicture(path)
End Sub
Private Sub Label1_Click()
MultiPage1.Style = 2
End Sub
Private Sub MultiPage1_Change()
MsgBox MultiPage1.Value
MultiPage1.Value = 3
End Sub
命令栏操作(略)
功能区操作(略)
代码操作代码(略)