- Код: Выделить всё
Sub DataExtract()
'Option Explicit
' Create a connection object.
Dim cnPubs As ADODB.Connection
Set cnPubs = New ADODB.Connection
' Provide the connection string.
Dim strConn As String
'Use the SQL Server OLE DB Provider.
strConn = "PROVIDER=SQLOLEDB;"
'Connect to the Pubs database on the local server.
strConn = strConn & "DATA SOURCE=galaxy-test\test_galaxy;INITIAL CATALOG=data_zl;"
'Use an integrated login.
strConn = strConn & " User ID=supervisor; Password=ghbdtn;"
'Now open the connection.
cnPubs.Open strConn
' Create a recordset object.
Dim rsPubs As ADODB.Recordset
Set rsPubs = New ADODB.Recordset
With rsPubs
' Assign the Connection object.
.ActiveConnection = cnPubs
' Extract the required records.
.Open "SELECT top 1 T$PUTGSM.F$PROBEGALL FROM data_zl.dbo.T$PUTGSM where T$PUTGSM.F$NREC='0001000000000022h'"
' Copy the records into cell A1 on Sheet1.
Sheet1.Range("A1").CopyFromRecordset rsPubs
' Tidy up
.Close
End With
cnPubs.Close
Set rsPubs = Nothing
Set cnPubs = Nothing
End Sub
ругается на run-time 424 --Sheet1.Range("A1").CopyFromRecordset rsPubs. библиотеки подключил: microsoft active x data object library, recordset, microsoft ado, ole db provider. что еще необходимо почему ругается?