明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1454|回复: 1

[求助]急!在线等。在VB中可以实现的怎么在VBA中不行

[复制链接]
发表于 2007-11-10 23:11:00 | 显示全部楼层 |阅读模式
本帖最后由 bophy20010 于 2011-8-26 13:03 编辑

<H1 style="LINE-HEIGHT: 50%; mso-pagination: none"><FONT size=1>在别的网站上找了个可以修改</FONT><SPAN lang=EN-US><FONT size=1>MSFlexGrid1控件数据<BR>用一个text和一个MsFlexGrid进行数据的录入有点类似Excel,运行时将Text1的BorderStyle设为0。但在VBA 中却不行,不同的是vb中:Private Sub Text1_KeyPress(ByVal KeyAscii AsInteger) <BR>和VBA中:Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)。代码如下:</FONT></SPAN></H1>
<H1 style="LINE-HEIGHT: 50%; mso-pagination: none"><SPAN lang=EN-US>
<P><FONT size=1></FONT></P></SPAN></H1>
<H2 style="LINE-HEIGHT: 50%; mso-pagination: none"><FONT size=1>Dim i As Integer '定义一个整型变量<BR>Private Sub Form_Activate()<BR>MSFlexGrid1.Rows = 13 '设置MSFlexGrid表格的总行数<BR>MSFlexGrid1.Cols = 6 '设置MSFlexGrid表格的总列数<BR>'设置MSFlexGrid表格的列宽<BR>MSFlexGrid1.ColWidth(0) = 12 * 25 * 1<BR>MSFlexGrid1.ColWidth(1) = 12 * 25 * 3<BR>MSFlexGrid1.ColWidth(2) = 12 * 25 * 6<BR>MSFlexGrid1.ColWidth(3) = 12 * 25 * 3<BR>MSFlexGrid1.ColWidth(4) = 12 * 25 * 4<BR>MSFlexGrid1.ColWidth(5) = 12 * 25 * 4<BR>'设置MSFlexGrid表格的固定行数<BR>MSFlexGrid1.FixedRows = 1<BR>'设置MSFlexGrid表格的固定列数<BR>MSFlexGrid1.FixedCols = 1<BR>'设置MSFlexGrid表格的表头信息<BR>MSFlexGrid1.TextMatrix(0, 0) = "xh"<BR>MSFlexGrid1.TextMatrix(0, 1) = " 批号"<BR>MSFlexGrid1.TextMatrix(0, 2) = " 药品名称"<BR>MSFlexGrid1.TextMatrix(0, 3) = " 规格"<BR>MSFlexGrid1.TextMatrix(0, 4) = " 厂家/产地"<BR>MSFlexGrid1.TextMatrix(0, 5) = " 单位"<BR>'为MSFlexGrid表格设置序号<BR>For i = 1 To 12<BR>MSFlexGrid1.TextMatrix(i, 0) = i<BR>Next i<BR>Text1.Visible = True 'text1可见<BR>'指定text1控件在MSFlexGrid1表格中的大小及位置<BR>Text1.Width = MSFlexGrid1.CellWidth<BR>Text1.Height = MSFlexGrid1.CellHeight<BR>Text1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left<BR>Text1.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top<BR>'text1获得焦点<BR>Text1.SetFocus<BR>End Sub<BR>Private Sub MSFlexGrid1_Click() '单击单元格<BR>If MSFlexGrid1.Col &lt;= 5 And MSFlexGrid1.Row &lt;= 12 Then<BR>'指定text1控件在MSFlexGrid1表格中的大小及位置<BR>Text1.Width = MSFlexGrid1.CellWidth<BR>Text1.Height = MSFlexGrid1.CellHeight<BR>Text1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left<BR>Text1.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top<BR>'赋值给MSFlexGrid1.Text<BR>Text1.Text = MSFlexGrid1.Text<BR>'text1可见<BR>Text1.Visible = True<BR>'text1获得焦点<BR>Text1.SetFocus<BR>End If<BR>End Sub<BR>Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)<BR>MSFlexGrid1_Click<BR>End Sub<BR>Private Sub Text1_KeyPress(KeyAscii As Integer)<BR>If KeyAscii = vbKeyEscape Then '当按下ESC键时<BR>Text1.Visible = False 'text1不可见<BR>MSFlexGrid1.SetFocus 'MSFlexGrid1获得焦点<BR>Exit Sub<BR>End If<BR>If KeyAscii = vbKeyReturn Then '当按下回车键时<BR>'赋值给text1.text<BR>MSFlexGrid1.Text = Text1.Text<BR>If MSFlexGrid1.Col &lt; 5 Then<BR>MSFlexGrid1.Col = MSFlexGrid1.Col + 1<BR>Else<BR>MSFlexGrid1.Row = MSFlexGrid1.Row + 1<BR>MSFlexGrid1.Col = 1<BR>End If<BR>'指定text1控件在MSFlexGrid1表格中的大小及位置<BR>Text1.Width = MSFlexGrid1.CellWidth<BR>Text1.Height = MSFlexGrid1.CellHeight<BR>Text1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left<BR>Text1.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top<BR>'赋值给MSFlexGrid1.Text<BR>Text1.Text = MSFlexGrid1.Text<BR>Text1.SetFocus 'text1获得焦点<BR>End If<BR>End Sub<BR>Private Sub Command1_Click()<BR>End<BR>End Sub </FONT>
<P></P></H2>
<H2><FONT size=1></FONT>&nbsp;</H2>
发表于 2008-2-20 22:30:00 | 显示全部楼层
对象不同
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-26 11:54 , Processed in 0.158528 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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