If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Process many Excel files in VBA

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-15-07, 19:57
JerryDal JerryDal is offline
Registered User
 
Join Date: Jan 2002
Location: Bay Area
Posts: 473
Process many Excel files in VBA

I have similarly formatted daily Excel files in a directory c:\Data\Transactions. From a main workbook or what I call a template, I want to open each one and store the data. Each file has the date as part of the file name.

How can I capture the names of all the files in one directory from VBA. I will put the file names in an array and open each one, copy the data, then close the file.

Jerry
Reply With Quote
  #2 (permalink)  
Old 02-15-07, 21:00
shades shades is offline
Registered User
 
Join Date: Oct 2003
Posts: 1,091
If that is all you have in that directory then I don't think you need to put them in an aray through VBA. Let me find something that goes through every file in a specified directory. It might not be until tomorrow.
__________________
old, slow, and confused
but at least I'm inconsistent!

Rich
(retired Excel 2003 user, 3/28/2008)

How to ask a question on forums
Reply With Quote
  #3 (permalink)  
Old 02-16-07, 07:25
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
There have been a few similar questions in the MSAccess forums - might be worth a look.
I think Dir() works in Excel, so there's a start...
__________________
George
Twitter | Blog
Reply With Quote
  #4 (permalink)  
Old 02-16-07, 13:40
shades shades is offline
Registered User
 
Join Date: Oct 2003
Posts: 1,091
Code:
Sub ProcessAll(sPath As String) 
    Dim Wb As Workbook, sFile As String 
     
    sFile = Dir(sPath & "*.xls") 
     'Loop through all .xls-Files in that path
    Do While sFile <> "" 
         
        Set Wb = Workbooks.Open(sPath & sFile) 
         
         'Do something with that Workbook, insert whatever you want to do here
        Debug.Print Wb.Name 
         'You can save it, if you like, here it's not saved
        Wb.Close False 
         
        sFile = Dir 
    Loop 
End Sub
__________________
old, slow, and confused
but at least I'm inconsistent!

Rich
(retired Excel 2003 user, 3/28/2008)

How to ask a question on forums
Reply With Quote
  #5 (permalink)  
Old 02-16-07, 13:55
JerryDal JerryDal is offline
Registered User
 
Join Date: Jan 2002
Location: Bay Area
Posts: 473
Thanks shades. Your VBA solution to process every Excel file in a specific folder does the job.
Jerry
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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