翔羽 发表于 2005-8-22 10:43:00

VB和VBA代码移植问题

在VB中加一个flexgrid,text,label,combox控件 代码可以正常运行,但是当在VBA环境下运行以下代码的时候会提示错误,请大家帮我看看,看究竟是什么原因?

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
页: [1]
查看完整版本: VB和VBA代码移植问题