+ Reply to Thread
Results 1 to 5 of 5

Open all files in subfolders

  1. #1
    linglc
    Guest

    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. #2
    Ron de Bruin
    Guest

    Re: 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" <[email protected]> wrote in message news:[email protected]...
    >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. #3
    Bob Phillips
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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. #4
    linglc
    Guest

    Re: 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" <[email protected]> wrote in message
    > news:[email protected]...
    > > 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. #5
    Bob Phillips
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1