VB和VBA代码移植问题
<P>在VB中加一个flexgrid,text,label,combox控件 代码可以正常运行,但是当在VBA环境下运行以下代码的时候会提示错误,请大家帮我看看,看究竟是什么原因?</P><P><BR>Option Explicit</P>
<P>Private Sub Combo1_Change()</P>
<P>End Sub</P>
<P>Private Sub Combo1_Exit(ByVal Cancel As MSForms.ReturnBoolean)<BR>Combo1.Visible = False<BR>MSFlexGrid1.SetFocus<BR>End Sub</P>
<P>Private Sub Combo1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)<BR>Dim i As Integer, bSame As Boolean<BR>If KeyAscii = vbKeyEscape Then<BR> Combo1.Visible = False<BR> MSFlexGrid1.SetFocus<BR> Exit Sub<BR>End If<BR>If KeyAscii = vbKeyReturn Then<BR> MSFlexGrid1.text = Combo1.text<BR> Combo1.Visible = False<BR> MSFlexGrid1.SetFocus<BR> With Combo1<BR> bSame = False<BR> For i = 0 To .ListCount<BR> If .text = .List(i) Then bSame = True<BR> Next i<BR> If Not bSame Then .AddItem .text<BR> End With<BR>End If</P>
<P>End Sub</P>
<P>Private Sub MSFlexGrid1_Click()<BR>Dim c As Integer, r As Integer<BR>With MSFlexGrid1<BR> c = .Col: r = .Row<BR> If r <= 2 Then<BR> <BR> Text1.Left = .Left + .ColPos(c)<BR> Text1.Top = .Top + .RowPos(r)<BR> Text1.width = .ColWidth(c)<BR> Text1.height = .RowHeight(r)<BR> Text1 = .text<BR> Text1.Visible = True<BR> Text1.SetFocus<BR> Else<BR> Combo1.Left = .Left + .ColPos(c)<BR> Combo1.Top = .Top + .RowPos(r)<BR> Combo1.width = .ColWidth(c)<BR> Combo1.text = .text<BR> Combo1.Visible = True<BR> Combo1.SetFocus<BR> End If<BR>End With</P>
<P><BR>End Sub</P>
<P>Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)<BR>If KeyAscii = vbKeyReturn Then<BR> Call MSFlexGrid1_Click<BR>End If<BR>End Sub</P>
<P>Private Sub Text1_Change()</P>
<P>End Sub</P>
<P>Private Sub Text1_Exit(ByVal Cancel As MSForms.ReturnBoolean)</P>
<P><BR>MSFlexGrid1.SetFocus<BR>Text1.Visible = False</P>
<P>End Sub</P>
<P>Private Sub Text1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)<BR>If KeyAscii = vbKeyEscape Then<BR> Text1.Visible = False<BR> MSFlexGrid1.SetFocus<BR> Exit Sub<BR>End If<BR>If KeyAscii = vbKeyReturn Then<BR> MSFlexGrid1.text = Text1.text<BR> Text1.Visible = False<BR> MSFlexGrid1.SetFocus<BR>End If<BR>End Sub</P>
<P>Private Sub UserForm_Initialize()<BR>Dim i As Integer<BR>With MSFlexGrid1<BR> .Cols = 5<BR> .Rows = 5<BR> For i = 0 To 4<BR> .RowHeight(i) = 300<BR> Next i<BR>End With<BR>For i = 1 To 10<BR> Combo1.AddItem i<BR>Next i<BR>Label1.Caption = "在第一、二行中,双击左键,会出现一文字框(TextBox)..." & vbCr & _<BR> "而第三、四行,会出现选择类表单(ComboBox)..." & vbCr & _<BR> "输入完毕后按下Enter键,资料即可保留于MSFlexGrid中," & vbCr & _<BR> "而按下Esc键则取消输入..."<BR>MSFlexGrid1.SetFocus<BR>Combo1.Visible = False<BR>Text1.Visible = False<BR>End Sub<BR></P>
页:
[1]