我在RSview32中用ADO进行历史数据采集时,写了一段VBA程序,但在运行的过程当中,编译没有任何错误,但运行时却出现错误,无法将数据写入到EXCEL中去!不知哪位高人能帮我看一下这段程序,能帮我介绍一下,错误到底出在哪里了!十分感谢您的帮助!
Public Sub jk()
On Error GoTo ErrHandler
Set RSEx = CreateObject("excel.application")
With RSEx
.workbooks.Add
.Visible = True
.worksheets("sheet1").activate
.Rows(1).Font.Bold = True
.Columns.horizontalalignment = -4108
.Columns(1).columnwidth = 12
.Columns(2).columnwidth = 12
.Columns(3).columnwidth = 20
.Columns(4).columnwidth = 20
.Columns(5).columnwidth = 20
.range("a2").Value = "采样日期"
.range("b2").Value = "采样时间"
.range("c2").Value = "流量一"
.range("d2").Value = "流量二"
.range("e2").Value = "流量三"
End With
Set RScn = CreateObject("adodb.connection")
RScn.open "driver={microsoft dbase driver(*.dbf)};DBQ=E:\二系列净化\设计程序备份\烟气净化\DLGLOG\RSVIEW"
Set rs = CreateObject("adodb.recordset")
rs.open "select * from RSVIEW where Date between #2008/11/30# and #2008/12/01#", RScn
inti = 3
Do While Not rs.EOF
With RSEx.activesheet
.cells(inti, 1).Value = rs("date")
.cells(inti, 2).Value = rs("time")
.cells(inti, 3).Value = rs("Trend\StartTime")
.cells(inti, 4).Value = rs("Analog\FT002")
.cells(inti, 5).Value = rs("Analog\FT003")
End With
rs.movenext
inti = inti + 1
Loop
ErrHandler:
gActivity.Log "RSView32 VBA Error " & Err.Number & ": " & Err.Description, _
roActivityError
resume next
End Sub