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

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>&nbsp;&nbsp;&nbsp; Combo1.Visible = False<BR>&nbsp;&nbsp;&nbsp; MSFlexGrid1.SetFocus<BR>&nbsp;&nbsp;&nbsp; Exit Sub<BR>End If<BR>If KeyAscii = vbKeyReturn Then<BR>&nbsp;&nbsp;&nbsp; MSFlexGrid1.text = Combo1.text<BR>&nbsp;&nbsp;&nbsp; Combo1.Visible = False<BR>&nbsp;&nbsp;&nbsp; MSFlexGrid1.SetFocus<BR>&nbsp;&nbsp;&nbsp; With Combo1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bSame = False<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i = 0 To .ListCount<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If .text = .List(i) Then bSame = True<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next i<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Not bSame Then .AddItem .text<BR>&nbsp;&nbsp;&nbsp; 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>&nbsp;&nbsp;&nbsp; c = .Col: r = .Row<BR>&nbsp;&nbsp;&nbsp; If r &lt;= 2 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Text1.Left = .Left + .ColPos(c)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Text1.Top = .Top + .RowPos(r)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Text1.width = .ColWidth(c)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Text1.height = .RowHeight(r)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Text1 = .text<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Text1.Visible = True<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Text1.SetFocus<BR>&nbsp;&nbsp;&nbsp; Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Combo1.Left = .Left + .ColPos(c)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Combo1.Top = .Top + .RowPos(r)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Combo1.width = .ColWidth(c)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Combo1.text = .text<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Combo1.Visible = True<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Combo1.SetFocus<BR>&nbsp;&nbsp;&nbsp; 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>&nbsp;&nbsp;&nbsp; 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>&nbsp;&nbsp;&nbsp; Text1.Visible = False<BR>&nbsp;&nbsp;&nbsp; MSFlexGrid1.SetFocus<BR>&nbsp;&nbsp;&nbsp; Exit Sub<BR>End If<BR>If KeyAscii = vbKeyReturn Then<BR>&nbsp;&nbsp;&nbsp; MSFlexGrid1.text = Text1.text<BR>&nbsp;&nbsp;&nbsp; Text1.Visible = False<BR>&nbsp;&nbsp;&nbsp; MSFlexGrid1.SetFocus<BR>End If<BR>End Sub</P>
<P>Private Sub UserForm_Initialize()<BR>Dim i As Integer<BR>With MSFlexGrid1<BR>&nbsp;&nbsp;&nbsp; .Cols = 5<BR>&nbsp;&nbsp;&nbsp; .Rows = 5<BR>&nbsp;&nbsp;&nbsp; For i = 0 To 4<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .RowHeight(i) = 300<BR>&nbsp;&nbsp;&nbsp; Next i<BR>End With<BR>For i = 1 To 10<BR>&nbsp;&nbsp;&nbsp; Combo1.AddItem i<BR>Next i<BR>Label1.Caption = "在第一、二行中,双击左键,会出现一文字框(TextBox)..." &amp; vbCr &amp; _<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "而第三、四行,会出现选择类表单(ComboBox)..." &amp; vbCr &amp; _<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "输入完毕后按下Enter键,资料即可保留于MSFlexGrid中," &amp; vbCr &amp; _<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "而按下Esc键则取消输入..."<BR>MSFlexGrid1.SetFocus<BR>Combo1.Visible = False<BR>Text1.Visible = False<BR>End Sub<BR></P>
页: [1]
查看完整版本: VB和VBA代码移植问题