| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 905 人关注过本帖
标题:急求VB编程进行数据采集保存在EXCEL2003中的问题
只看楼主 加入收藏
crzzx
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-7-8
收藏
 问题点数:0 回复次数:2 
急求VB编程进行数据采集保存在EXCEL2003中的问题
请问如何在一个程序中多次调用同一个Excel文件,比如用Timer1控件每隔一定时间把数据保存进入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
    CommonDialog1.ShowOpen
If Len(CommonDialog1.FileName) >= 1 Then
  exApp.Workbooks.Open CommonDialog1.FileName   出错处   
  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
但是一进入Private Sub Timer1_Timer()这个里面运行到 exApp.Workbooks.Open CommonDialog1.FileName时就显示
实时错误'91',对象变量或With快变量未设置。

[[it] 本帖最后由 crzzx 于 2008-7-8 20:57 编辑 [/it]]

[[it] 本帖最后由 crzzx 于 2008-7-8 20:58 编辑 [/it]]
搜索更多相关主题的帖子: Excel 
2008-07-08 20:05
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
收藏
得分:0 
Set exApp = Nothing

第一次timer的时候exApp都成Nothing了,下一次哪里来的Workbooks?
2008-07-08 21:23
crzzx
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-7-8
收藏
得分:0 
谢谢,明白了!
2008-07-10 08:40
快速回复:急求VB编程进行数据采集保存在EXCEL2003中的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014327 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved