登录
首页 电脑编程
回帖 发帖
正文

主题:现有一简单的关于串口数采写入EXCEL的VBA源码程序让大家提意见。

点击:3128 回复:1

随便遍遍,请别见笑,请多提意见。
模块代码
Sub auto_open()
UserForm1.IeTimer1.Enabled = ValFalse
UserForm1.IeTimer1.Interval = 5000
UserForm1.Show
Application.OnUndo "Undo VB Procedure", "auto_open"
End Sub
Public j As Integer
采集窗体代码
Private Sub IeTimer1_Timer()
j = j + 1
Sheet1.Cells(2, 3).Value = j  
Sheet1.Cells(j + 1, 1).Value = j  
Sheet1.Cells(j + 1, 2).Value = j + 1 ''写采样值应为串口值MSComm1.Input
End Sub
Private Sub readdata_Click()  
IeTimer1.Enabled = ValTrue
End Sub
Private Sub tingzhidu_Click()
IeTimer1.Enabled = ValFalse
End Sub
Private Sub tuichu_Click()
Sheet1.Protect ([711001])
 End        
End Sub
Private Sub UserForm_Activate()  
Sheet1.Unprotect ([711001])
Sheet1.Cells(1, 1).Value = "序号"
Sheet1.Cells(1, 2).Value = "测量值"
Sheet1.Cells(1, 3).Value = "测量个数"
IeTimer1.Enabled = ValFalse
Sheet1.Activate
j = Sheet1.Cells(2, 3).Value    
End Sub
Private Sub xtchushi_Click()
Dim i, k As Integer
IeTimer1.Enabled = ValFalse
Sheet1.Cells(2, 3).Value = 0                
For i = 1 To 2
 For k = 1 To j
  Sheet1.Cells(k + 1, i).Value = ""
 Next k
Next i
j = 0
End Sub
附程序:
附件:
[本地下载]
最后修改:2004-7-22 13:29:55
04-07-22 13:27
请帮忙在VBA程序写入EXCEL时数据一直显示在最后一个
04-07-22 14:02

工控新闻

更多新闻资讯