Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Open all files in subfolders

I have many level 1 subfolders with examples shown below

Country
America
Germany
Japan
France

In each subfolders are some excel files. I want to paste some values from a
master file to all the excel files found in the subfolders. Anyone can help?
Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Open all files in subfolders

Hi linglc

You can adapt this macro
http://www.rondebruin.nl/fso.htm

If you need help post back



--
Regards Ron de Bruin
http://www.rondebruin.nl



"linglc" wrote in message ...
I have many level 1 subfolders with examples shown below

Country
America
Germany
Japan
France

In each subfolders are some excel files. I want to paste some values from a
master file to all the excel files found in the subfolders. Anyone can help?
Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Open all files in subfolders


Sub LoopFolders()

Set oFSO = CreateObject("Scripting.FileSystemObject")

selectFiles "c:\MyTest"

Set oFSO = Nothing

End Sub


'---------------------------------------------------------------------------
Sub selectFiles(sPath)
'---------------------------------------------------------------------------
Dim Folder As Object
Dim Files As Object
Dim file As Object
Dim fldr

Set Folder = oFSO.GetFolder(sPath)

For Each fldr In Folder.Subfolders
selectFiles fldr.Path
Next fldr

For Each file In Folder.Files
If file.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=file.Path
End If
Next file

End Sub

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"linglc" wrote in message
...
I have many level 1 subfolders with examples shown below

Country
America
Germany
Japan
France

In each subfolders are some excel files. I want to paste some values from

a
master file to all the excel files found in the subfolders. Anyone can

help?
Thanks.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Open all files in subfolders

Bob,

Thanks for your reply. However I have some problem with this row

Set Folder = oFSO.GetFolder(sPath)

I get the message -- run time error '424' : object required

Do you know why?


--
help needed


"Bob Phillips" wrote:


Sub LoopFolders()

Set oFSO = CreateObject("Scripting.FileSystemObject")

selectFiles "c:\MyTest"

Set oFSO = Nothing

End Sub


'---------------------------------------------------------------------------
Sub selectFiles(sPath)
'---------------------------------------------------------------------------
Dim Folder As Object
Dim Files As Object
Dim file As Object
Dim fldr

Set Folder = oFSO.GetFolder(sPath)

For Each fldr In Folder.Subfolders
selectFiles fldr.Path
Next fldr

For Each file In Folder.Files
If file.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=file.Path
End If
Next file

End Sub

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"linglc" wrote in message
...
I have many level 1 subfolders with examples shown below

Country
America
Germany
Japan
France

In each subfolders are some excel files. I want to paste some values from

a
master file to all the excel files found in the subfolders. Anyone can

help?
Thanks.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Open all files in subfolders

Sorry, I missed one vital line.

AT the very start, before the first sub, add

Dim oFSO As Object

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"linglc" wrote in message
...
Bob,

Thanks for your reply. However I have some problem with this row

Set Folder = oFSO.GetFolder(sPath)

I get the message -- run time error '424' : object required

Do you know why?


--
help needed


"Bob Phillips" wrote:


Sub LoopFolders()

Set oFSO = CreateObject("Scripting.FileSystemObject")

selectFiles "c:\MyTest"

Set oFSO = Nothing

End Sub



'---------------------------------------------------------------------------
Sub selectFiles(sPath)

'---------------------------------------------------------------------------
Dim Folder As Object
Dim Files As Object
Dim file As Object
Dim fldr

Set Folder = oFSO.GetFolder(sPath)

For Each fldr In Folder.Subfolders
selectFiles fldr.Path
Next fldr

For Each file In Folder.Files
If file.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=file.Path
End If
Next file

End Sub

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"linglc" wrote in message
...
I have many level 1 subfolders with examples shown below

Country
America
Germany
Japan
France

In each subfolders are some excel files. I want to paste some values

from
a
master file to all the excel files found in the subfolders. Anyone can

help?
Thanks.








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
Opening files in folders and subfolders bestie22 Excel Discussion (Misc queries) 1 September 19th 06 05:23 PM
Map/List of folders, subfolders & files Bogdan Excel Programming 5 June 11th 06 06:01 PM
replace text in files within subfolders pieros Excel Programming 0 November 1st 05 01:19 PM
copy subfolders, replace text in files and save files in copied subfolders pieros Excel Programming 0 November 1st 05 12:08 PM
Modify - look at files within subfolders Steph[_3_] Excel Programming 1 October 8th 04 06:51 PM


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