注册 登录
编程论坛 新人交流区

求助用VB编程进行数据采集保存在EXCEL2003中的问题

wfr666 发布于 2007-11-03 15:11, 1522 次点击
现在公司要开发一套自动测试系统,要在EXCEL2003中保存大量的数据,可是在用VB做好界面及各设备的控制命令后,在运行过程中,采集完数据后,自动退出EXCEL2003时,总是弹出对话框,询问我是否要保存数据,还要我选择保存的路径,其实保存的路径和保存的命令我都写在程序里了,不知道为什么EXCEL2003在关毕时还在询问我,想各位高手帮我一下,要自动关闭EXCEL2003保存资料退出,用什么VB的命令啊,谢谢了哦!
1 回复
#2
crzzx2008-07-08 20:43
帮个忙
我想问下你,你是用什么方法将数据采集卡采集到的数据不断地保存在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
1