帮个忙
我想问下你,你是用什么方法将数据采集卡采集到的数据不断地保存在excel里面?,我现在也在做这个,可我打开一次excel文件,第二次就不行了.下面是我的程序代码,帮我看下好吗?
Dim exApp As Excel.Application
Dim i, k As Integer
Private Sub Command1_Click()
CommonDialog1.ShowOpen
If Len(CommonDialog1.FileName) >= 1 Then
exApp.Workbooks.Open CommonDialog1.FileName
For i = 1 To 5
Range(Cells(i, 1), Cells(i, 1)) = "aa"
Range(Cells(i, 2), Cells(i, 2)) = "aa"
Range(Cells(i, 3), Cells(i, 3)) = "aa"
Range(Cells(i, 4), Cells(i, 4)) = "aa"
Next
exApp.ActiveWorkbook.Save
exApp.ActiveWorkbook.Close
End If
exApp.Quit
Set exApp = Nothing
Timer1.Enabled = True
Timer1.Interval = 3000
End Sub
Private Sub Form_Load()
Set exApp = New Excel.Application
End Sub
Private Sub Timer1_Timer()
k = k + 1
If Len(CommonDialog1.FileName) >= 1 Then
[color=Magenta]exApp.Workbooks.Open CommonDialog1.FileName 当运行到这里就出错,错误是:对象变量或With块变量未设置[/color]
Range(Cells(k, 6), Cells(k, 6)) = k
Range(Cells(k, 7), Cells(k, 7)) = k
Range(Cells(k, 8), Cells(k, 8)) = k
Range(Cells(k, 9), Cells(k, 9)) = k
exApp.ActiveWorkbook.Save
exApp.ActiveWorkbook.Close
End If
exApp.Quit
Set exApp = Nothing
End Sub