A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Hi
Could you have a try with this one ?
Sub getData()
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H1
Dim conn As Object
Dim rs As Object
Dim strCon As String
Dim strSQL As String
Dim x As Long
'change the path from ThisWorkbook.FullName to your other workbook
Set conn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ThisWorkbook.FullName & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1;ReadOnly=False;Format=xls"" "
' Extended properties for Excel 2000/2002/2003 : Excel 8.0
' Extended properties for Excel 97 :Excel 97
' HDR header row ye sor no
' IMEX mixed data type
conn.Open strCon
'Change the name in [ ] if incorrect
strSQL = "SELECT [TimeStamp], [HourlyTonnage] FROM [Tonnage] "
rs.Open strSQL, conn, adOpenStatic, adLockOptimistic, adCmdText
Worksheets("notcompleted").Range("A1").CurrentRegion.Clear
For x = 0 To rs.Fields.Count - 1
Worksheets("notcompleted").Range("A1").Offset(0, x) = rs.Fields(x).Name
Next x
Worksheets("notcompleted").Range("A2").CopyFromRecordset rs
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
End Sub
regards
JY
I am attempting to use ODBC, not OLEDB. The reasons for this are that ultimately I will be pulling from a 3rd party software that only offers ODBC. This may just be a problem with the way the excel ODBC driver works, and won't impact it in my final production environment - it was just something I came across and figured I should report it.