您好,我在行中收到错误 [Runtime Error '448': Named argument not found]
Set qt = ThisWorkbook.Sheets(server_hostname).ListObjects.Add(Connection:=oRS, _
Destination:=ThisWorkbook.Sheets(server_hostname).Range("A1")).QueryTable
完整的源代码如下,
Sub getavgcpu(server_hostname)
Dim oCn As ADODB.Connection
Dim oRS As ADODB.Recordset
Dim ConnString As String
Dim SQL As String
Dim qt As QueryTable
ThisWorkbook.Sheets(server_hostname).Activate
ConnString = "Driver={MySQL ODBC 5.1 Driver};Server=localhost; _
Database=test; User=root;Password=123456;Option=3;"
Set oCn = New ADODB.Connection
oCn.ConnectionString = ConnString
oCn.Open
SQL = "SELECT cpu_max_unix_0.LOGDATE as 'Date of Month', cpu_max_unix_0.CPU as 'CPU Utilization %' FROM test.cpu_max_unix cpu_max_unix_0 where (cpu_max_unix_0.LOGDATE between '" & fromDateStr & "' and '" & toDateStr & "') And (cpu_max_unix_0.SERVER_NAME='" & server_hostname & "') Order By cpu_max_unix_0.LOGDATE"
Set oRS = New ADODB.Recordset
oRS.Source = SQL
oRS.ActiveConnection = oCn
oRS.Open
'Set qt = ThisWorkbook.Sheets(server_hostname).QueryTables.Add(Connection:=oRS, _
'Destination:=ThisWorkbook.Sheets(server_hostname).Range("A1"))
Set qt = ThisWorkbook.Sheets(server_hostname).ListObjects.Add(Connection:=oRS, _
Destination:=ThisWorkbook.Sheets(server_hostname).Range("A1")).QueryTable
qt.Refresh
If oRS.State <> adStateClosed Then
oRS.Close
End If
If Not oRS Is Nothing Then Set oRS = Nothing
If Not oCn Is Nothing Then Set oCn = Nothing
End Sub
请帮忙!