Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default opening workbooks in subfolders

My boss (who lies awake at night dreaming up these things) wants a workbook
in folder X which reads in the contents of all the (one sheet) workbooks in
sub-folders of X at the click of a button. Neither the sub-folder names nor
the names of the workbooks within them are constant.

I'm sure I'm not the only person who's had to do this and this is way beyond
my job description, so I'm writing in hope that if anyone has useful code
snippets, they'll post them.

Thanks in advance!
Sian
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default opening workbooks in subfolders

Sian,

So let me be sure I understand. Your boss want you to open a workbook the
name of which you don't know that resides in a sub folder you don't know the
name of and in any case is liable to change. Now le me think!!!


Mike

"Sian" wrote:

My boss (who lies awake at night dreaming up these things) wants a workbook
in folder X which reads in the contents of all the (one sheet) workbooks in
sub-folders of X at the click of a button. Neither the sub-folder names nor
the names of the workbooks within them are constant.

I'm sure I'm not the only person who's had to do this and this is way beyond
my job description, so I'm writing in hope that if anyone has useful code
snippets, they'll post them.

Thanks in advance!
Sian

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default opening workbooks in subfolders


Ok, obviously I didn't explain myself very well?
It would look like this: Folder X\summarysheet.xls

would read in info from
Folder X\Apples\appleslaunch.xls
Folder X\Pears\pearslaunch.xls
etc.

except that I don't know "Apples", "Pears", "appleslaunch.xls" etc. so I
guess I'd have to read all the subfolders into an array and then read in file
names for each array element...
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default opening workbooks in subfolders

Try this code. It copies every shett in every workbook

Sub GetWorksheets()

strFolder = ThisWorkbook.Path

Set fso = CreateObject _
("Scripting.FileSystemObject")
Set folder = _
fso.GetFolder(strFolder)

Call GetWorksheetsSubFolder(strFolder + "\")
End Sub

Sub GetWorksheetsSubFolder(strFolder)
Set fso = CreateObject _
("Scripting.FileSystemObject")

Set folder = _
fso.GetFolder(strFolder)

If folder.subfolders.Count 0 Then
For Each sf In folder.subfolders
On Error GoTo 100
Call GetWorksheetsSubFolder(strFolder + sf.Name + "\")
100 Next sf
End If
'folder size in bytes
On Error GoTo 200
For Each fl In folder.Files
If Right(UCase(fl.Name), 4) = ".XLS" Then
Workbooks.Open Filename:=strFolder & fl.Name
Set oldbk = ActiveWorkbook
For Each sht In oldbk.Sheets
With ThisWorkbook
sht.Copy after:=.Sheets(.Sheets.Count)
End With
Next sht
oldbk.Close
End If
Next fl

200 On Error GoTo 0

End Sub


"Mike H" wrote:

Sian,

So let me be sure I understand. Your boss want you to open a workbook the
name of which you don't know that resides in a sub folder you don't know the
name of and in any case is liable to change. Now le me think!!!


Mike

"Sian" wrote:

My boss (who lies awake at night dreaming up these things) wants a workbook
in folder X which reads in the contents of all the (one sheet) workbooks in
sub-folders of X at the click of a button. Neither the sub-folder names nor
the names of the workbooks within them are constant.

I'm sure I'm not the only person who's had to do this and this is way beyond
my job description, so I'm writing in hope that if anyone has useful code
snippets, they'll post them.

Thanks in advance!
Sian

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default opening workbooks in subfolders



This worked perfectly first time - THANK YOU!!!!
Reply
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
run macro on all closed workbooks in folder and subfolders spence Excel Programming 3 May 2nd 07 07:52 PM
Opening Workbooks Brent Excel Programming 4 April 9th 07 10:30 PM
Opening files in folders and subfolders bestie22 Excel Discussion (Misc queries) 1 September 19th 06 05:23 PM
copy subfolders, replace text in files and save files in copied subfolders pieros Excel Programming 0 November 1st 05 12:08 PM


All times are GMT +1. The time now is 11:48 PM.

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"