Sub Test()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strConnection As String
Dim sql As String
' Create the connection string.
strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" _
& "Data Source='d:\Downloads\_______output.xls';" _
& "Extended Properties='Excel 8.0;HDR=NO;IMEX=1';"
' Create the Connection and Recordset objects.
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
sql = "SELECT * FROM [Лист1$A1:E10]"
' Open the connection and execute.
conn.Open strConnection
Set rs = conn.Execute(sql)
' Check we have data.
If Not rs.EOF Then
' Transfer result.
ActiveSheet.Range("A1").CopyFromRecordset rs
' Close the recordset
rs.Close
Else
MsgBox "Error: No records returned.", vbCritical
End If
' Clean up
If CBool(conn.State And adStateOpen) Then conn.Close
Set conn = Nothing
Set rs = Nothing
End Sub
|