首页上一页 1 下一页尾页 1 条记录 1/1页
求助:使用EXCEL querytable.add 无效的过程调用或参数
发表在VB答疑区
2012-11-20
是否精华
是
否
版块置顶:
是
否
使用EXCEL querytable.add 无效的过程调用或参数 代码如下:
Private Sub CommandButton3_Click()
On Error GoTo exl:
Dim RSEXCEL As New Excel.Application
Dim RSBOOK As New Excel.Workbook
Dim RSSHEET As New Excel.Worksheet
Dim RSQUE As New Excel.QueryTable
Dim RS1 As ADODB.Recordset
Set RS1 = New ADODB.Recordset
RS1.Open "select datetime as 时间, value as 值, tag as 标签名, status AS 描述 from fix " & _
"where (datetime>={ts'" & "2012-11-17 00:00:00" & "'} and datetime<={ts'" & "2012-11-17 12:12:12" & "'})" & "and interval='00:10:00'" & _
"AND TAG='ADO_AI1'" & "and value is not null", DB00, adOpenDynamic, adLockBatchOptimistic, -1
Set RSEXCEL = CreateObject("EXCEL.APPLICATION")
Set RSBOOK = RSEXCEL.Workbooks().Add
Set RSSHEET = RSBOOK.Worksheets("sheet1")
Set RSQUE = RSSHEET.QueryTables.Add(RS1, RSSHEET.Range("A1"))
RSQUE.Refresh
Exit Sub
exl:
RSEXCEL.Quit
Set RSEXCEL = Nothing
Set RSBOOK = Nothing
Set RSSHEET = Nothing
RS1.Close
End Sub
Private Sub CommandButton3_Click()
On Error GoTo exl:
Dim RSEXCEL As New Excel.Application
Dim RSBOOK As New Excel.Workbook
Dim RSSHEET As New Excel.Worksheet
Dim RSQUE As New Excel.QueryTable
Dim RS1 As ADODB.Recordset
Set RS1 = New ADODB.Recordset
RS1.Open "select datetime as 时间, value as 值, tag as 标签名, status AS 描述 from fix " & _
"where (datetime>={ts'" & "2012-11-17 00:00:00" & "'} and datetime<={ts'" & "2012-11-17 12:12:12" & "'})" & "and interval='00:10:00'" & _
"AND TAG='ADO_AI1'" & "and value is not null", DB00, adOpenDynamic, adLockBatchOptimistic, -1
Set RSEXCEL = CreateObject("EXCEL.APPLICATION")
Set RSBOOK = RSEXCEL.Workbooks().Add
Set RSSHEET = RSBOOK.Worksheets("sheet1")
Set RSQUE = RSSHEET.QueryTables.Add(RS1, RSSHEET.Range("A1"))
RSQUE.Refresh
Exit Sub
exl:
RSEXCEL.Quit
Set RSEXCEL = Nothing
Set RSBOOK = Nothing
Set RSSHEET = Nothing
RS1.Close
End Sub