LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default Copying the first row of wbooks with ADO

Hi
I would like to copy the first row of data from a number of wbooks using ADO
but for now the code below is just for 1 source wbook to the Log file.
It copies row 1 data from Test1.xls in the "C" directory to wherever Log.xls
is installed. The code works fine providing there is data in cell A1. But
if the first cell containing data in the source file (test1) is say C1, then
data is still copied into the Log file starting at A1 whereas it ought to be
C1. Empty columns elsewhere in the source file row1 are copied correctly
How can I rectify this?
Is my approach the best way to go about the process for multiple wbooks?

T.I.A.

Geoff

Option Explicit
Option Private Module

Sub Test2()
GetData "C:\Test1.xls", "Sheet1", "A1:IV1"
End Sub

Function GetData(SourceFile As Variant, SourceSheet As String, sourceRange
As _ String)
Dim rs As ADODB.Recordset
Dim szConnect As String
Dim szSQL As String

szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & SourceFile & ";" & _
"Extended Properties=""Excel 8.0;HDR=No"";"
szSQL = "SELECT * FROM [Sheet1$];"
Set rs = New ADODB.Recordset
rs.Open szSQL, szConnect, adOpenForwardOnly, adLockReadOnly, adCmdText
Workbooks("Log.xls").Sheets(1).Cells(1, 1).CopyFromRecordset rs, 1, _
rs.Fields.Count
rs.Close
Set rs = Nothing
End Function


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Which is faster, copying range to another set of ranges or copying tomemory? axwack Excel Programming 2 December 12th 07 01:19 PM
copying the Hyperlink function result without copying the actual formula mcheng Excel Worksheet Functions 2 June 9th 07 02:43 AM
Creating WBooks Geoff Excel Programming 5 June 9th 06 10:14 AM
RePost - Creating WBooks Geoff Excel Programming 4 June 9th 06 09:20 AM
show list of wbooks present into a dir sal21[_74_] Excel Programming 1 September 22nd 05 01:02 AM


All times are GMT +1. The time now is 02:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"