明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1789|回复: 4

[VBA]flexgrid控件问题

[复制链接]
发表于 2005-8-21 15:52:00 | 显示全部楼层 |阅读模式

我在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 <= 2 Then
       
        Text1.Left = .Left + .ColPos(c)
        Text1.Top = .Top + .RowPos(r)
        Text1.width = .ColWidth(c)
        Text1.height = .RowHeight(r)
        Text1 = .text
        Text1.Visible = True
        Text1.SetFocus
    Else
        Combo1.Left = .Left + .ColPos(c)
        Combo1.Top = .Top + .RowPos(r)
        Combo1.width = .ColWidth(c)
        Combo1.text = .text
        Combo1.Visible = True
        Combo1.SetFocus
    End If
End With


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

 楼主| 发表于 2005-8-21 15:54:00 | 显示全部楼层
程序代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
 楼主| 发表于 2005-8-21 19:48:00 | 显示全部楼层
怎么没有人回答阿~
发表于 2005-8-25 11:18:00 | 显示全部楼层
用用VSFLEXGRID控件看看,也许只要几行代码就可以搞定。
 楼主| 发表于 2005-8-26 14:50:00 | 显示全部楼层

to:ntchjie

 请问在VBA中怎样用VSFLEXGRID控件怎么快速实现我要的功能?

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 10:22 , Processed in 0.183386 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表