ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code needed to open files one at a time (https://www.excelbanter.com/excel-programming/394644-code-needed-open-files-one-time.html)

JohnUK

Code needed to open files one at a time
 
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

Tom Ogilvy

Code needed to open files one at a time
 
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

--
Regards,
Tom Ogilvy


"JohnUK" wrote:

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


JohnUK

Code needed to open files one at a time
 
Hi Tom,
Many thanks, I will try this later and let you know how I get on.
Regards
John

"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy


"JohnUK" wrote:

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


JohnUK

Code needed to open files one at a time
 
Hi Tom,
Many thanks, It worked a treat.
Take care
Regards
John

"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy


"JohnUK" wrote:

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



All times are GMT +1. The time now is 02:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com