• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Import big data from Closed Workbook

drom

New Member
Hi and thanks in advance!
I am Trying to get a big data from a closed workbook within the activesheet


I have seen the following macro:

Code:
Sub Pulldata()
'NEBU's code
On Error Resume Next:       Application.ScreenUpdating = False
  Dim wsXXX As String:      wsXXX = Hoja030.Name
  Dim wsSHT As String:      wsSHT = "PROJECTION"
Dim rs As ADODB.Recordset
Dim qry As String:          qry = "SELECT * FROM [" & wsSHT & "$] "
Dim fName As String:        fName = "X:\Projects\xRetail\Excels\AAAA.xlsx"
Dim Str As String:          Str = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & fName & ";" & "Extended Properties=Excel 12.0"
Dim xRow As Long:           xRow = 1
   
   
    Set rs = New ADODB.Recordset
    rs.Open qry, Str, adOpenUnspecified, adLockUnspecified


  'I would like to paste the data within the ActiveSheet
  'On ActiveSheet.cells(1,1)  so on  but don't know how to do this????????????

'Your range where you want to paste data to.CopyFromRecordset rs
Application.ScreenUpdating = True

End Sub




but dont know how to paste the data I guess this macro takes
so I am at present here:

'I would like to paste the data within the ActiveSheet
'but don't know how to do this????????????


'Your range where you want to paste data to.CopyFromRecordset rs
 
You need:
Code:
ActiveSheet.cells(1,1).CopyFromrecordset rs
though if you need the headers as well, you'll need to loop through the fields to get their names too.
 
Back
Top