LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tom Tom is offline
external usenet poster
 
Posts: 5
Default Looping thru files

I am trying to loop thru a group of files and get data from each sheet. I
do the looping fine and open each file with out a problem thanks to some
example from the forum(THANKS!). I am having a problem when I read the data.
I get the data from the current sheet and not from the sheet in the
spreadsheet I have opened. The spreadsheet does open but I keep reading the
data from the current sheet and not the open spreadsheet. How should I
correct this?

Thanks for the ideas and support!
Tom

Sub ADOFromExcelToAccess()
' exports data from the active worksheet to a table in an Access database
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim r As Long
Dim basebook As Workbook
Dim mybook As Workbook
Dim a As Long
Dim FNames As String
Dim MyPath As String
Dim SaveDriveDir As String
Dim test As Variant

SaveDriveDir = CurDir
MyPath = "E:\Excel\test"
FNames = Dir("*.xls")

Set basebook = ThisWorkbook
Do While FNames < ""
Set mybook = Workbooks.Open(FNames)

With mybook.Worksheets(1)

...............rest of code looping etc....
...............This works just cant get to the correct sheet.




 
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
Looping David T Excel Discussion (Misc queries) 2 August 30th 06 10:51 PM
Looping Andrew Clark[_2_] Excel Programming 1 December 20th 03 05:01 PM
Looping Stuart[_9_] Excel Programming 0 October 29th 03 11:31 PM
Need Looping Help [email protected] Excel Programming 2 October 29th 03 08:11 PM
looping to create multiple files jrh Excel Programming 1 July 23rd 03 07:09 PM


All times are GMT +1. The time now is 02:04 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"