|
我在vb中运行以下的程序好用,但是在vba中运行的时候总是提示我错误信息“对象不可用”
请斑竹和各位指教~~
程序主要用的是一个flexgrid控件,想实现在第一、二行中,单击左键,会出现一文字框
而第三、四行,会出现选择类表单(ComboBox)输入完毕后按下Enter键,资料即可保留于MSFlexGrid中,而按下Esc键则取消输入
Option Explicit
Private Sub Combo1_Change()
End Sub
Private Sub Combo1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Combo1.Visible = False
'MSFlexGrid1.SetFocus
End Sub
Private Sub Combo1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim i As Integer, bSame As Boolean
If KeyAscii = vbKeyEscape Then
Combo1.Visible = False
MSFlexGrid1.SetFocus
Exit Sub
End If
If KeyAscii = vbKeyReturn Then
MSFlexGrid1.text = Combo1.text
Combo1.Visible = False
MSFlexGrid1.SetFocus
With Combo1
bSame = False
For i = 0 To .ListCount
If .text = .List(i) Then bSame = True
Next i
If Not bSame Then .AddItem .text
End With
End If
End Sub
Private Sub MSFlexGrid1_Click()
Dim c As Integer, r As Integer
With MSFlexGrid1
c = .Col: r = .Row
If r
End Sub
Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
Call MSFlexGrid1_Click
End If
End Sub
Private Sub Text1_Change()
End Sub
Private Sub Text1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
'MSFlexGrid1.SetFocus
Text1.Visible = False
End Sub
Private Sub Text1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = vbKeyEscape Then
Text1.Visible = False
MSFlexGrid1.SetFocus
Exit Sub
End If
If KeyAscii = vbKeyReturn Then
MSFlexGrid1.text = Text1.text
Text1.Visible = False
MSFlexGrid1.SetFocus
End If
End Sub
Private Sub UserForm_Initialize()
Dim i As Integer
With MSFlexGrid1
.Cols = 5
.Rows = 5
For i = 0 To 4
.RowHeight(i) = 300
Next i
End With
For i = 1 To 10
Combo1.AddItem i
Next i
Label1.Caption = "在第一、二行中,双击左键,会出现一文字框(TextBox)..." & vbCr & _
"而第三、四行,会出现选择类表单(ComboBox)..." & vbCr & _
"输入完毕后按下Enter键,资料即可保留于MSFlexGrid中," & vbCr & _
"而按下Esc键则取消输入..."
'MSFlexGrid1.SetFocus
Combo1.Visible = False
Text1.Visible = False
End Sub
|
|