标题:请问:如何编写程序清除Excel中的内容?
取消只看楼主
liuminghui81
Rank: 1
等 级:禁止访问
帖 子:80
专家分:0
注 册:2007-11-22
得分:0 
你的是用recordset 的,

我的如下:
Dim objFileSystem As Object
     Dim objExcelText As Object
     Dim i, j As Integer
     Dim num As Integer
     Dim usrow As Integer
     
     num = 1
     Set xlApp = CreateObject("Excel.Application")
     xlApp.Visible = True
     Set xlBook = xlApp.Workbooks.Open("D:\材料追踪.xls")
     Set xlsheet = xlBook.Worksheets(1)
     xlsheet.Activate
     
     '清除Excel中原有的信息
     usrow = xlsheet.UsedRange.Rows.count
     For i = 5 To usrow
          xlsheet.Cells(i, 1) = ""
          xlsheet.Cells(i, 2) = ""
          xlsheet.Cells(i, 3) = ""
          xlsheet.Cells(i, 4) = ""
          xlsheet.Cells(i, 5) = ""
     Next
     xlsheet.Cells(2, 5) = "" '清除时间

     '将数组中的数据逐个复制到Ecxel报表的单元格中
     For i = 1 To (aNum - 1) / 5 ' aNum-1是个全局变量,数值从 cmdOK_Click()事件中得到,表示数组的大小
        For j = 1 To 5
            xlsheet.Cells(4 + i, j) = a(num)
            num = num + 1
        Next
     Next

     xlsheet.Cells(2, 5) = Format(Now, "AMPM(YYYY-MM-DD hh:mm:ss)")
     

感谢帮助!
2008-01-07 16:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-196305-1-1.html




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

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