Code needed to open files one at a time

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All,
Gosh havent been on here for a while.
Okay - I have a folder that has 10 to 30 files that I need to open one at a
time and export info from each file to a master workbook, close and start on
the next until they have all been covered.

I am in need of a piece of code that can find and open (regardless of file
name) close and start on the next.

I can fill in the code that will export the data, its the opening the files
one at a time I cant do.

Anyone out there that can help?

Many thanks
John
 
Dim sPath as String, sName as String
Dim bk as Workbook
sPath = "C:\Myfolder\"

sName = Dir(sPath & "*.xls")
do while sName <> ""
set bk = workbooks.Open(sPath & sName)


bk.close SaveChanges:=False
sName = Dir()
Loop
 
Hi Tom,
Many thanks, I will try this later and let you know how I get on.
Regards
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top