+ Reply to Thread
Results 1 to 4 of 4

Code only open the Folder's Excel but not Sub Folder's Excel. y?

  1. #1
    Forum Contributor
    Join Date
    03-12-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    276

    Code only open the Folder's Excel but not Sub Folder's Excel. y?

    Hi, i extracted a portion of my code as below. Its actually a combine file code. It works, but when i paste the folder path in A1, and run the marco, the code will onli open the Excel File inside the Folder, but not open the Sub Folder Excel file inside the Folder.
    I believe its somewhere below that need some amendment. Anyone can help?

    [code]
    path = Sheets("Sheet1").Range("A1").Value
    FileName = Dir(path & "*.xls*")
    Do While FileName <> ""
    Set wb = Workbooks.Open(FileName:=path & FileName, ReadOnly:=True)
    [code/]

  2. #2
    Valued Forum Contributor kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016/Work 2013 Pro Plus
    Posts
    627

    Re: Code only open the Folder's Excel but not Sub Folder's Excel. y?

    Can you show us what you are putting in A1?

  3. #3
    Forum Contributor
    Join Date
    03-12-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    276

    Re: Code only open the Folder's Excel but not Sub Folder's Excel. y?

    something like this

    C:\Users\abc\Desktop\testfolder\


    HOwever, within the testfolder, there are 2 excels file (which the marco open), but inside the testfolder are 3 subfolders that has 1 excel file each (marco did not open).
    Anyway, A1 is a formula cell, coz by default when u paste the path, it look like C:\Users\abc\Desktop\testfolder (without the last \ behind).
    Hence i paste in A2 and A1 = A2&"\"
    HOw do i put the "\" into my code also so that it can read A2 directly?

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,238

    Re: Code only open the Folder's Excel but not Sub Folder's Excel. y?

    to answer your simple question
    Please Login or Register  to view this content.
    For looping subfolders within a folder you need extra bit of code
    here is a version of it
    https://exceloffthegrid.com/vba-code...r-sub-folders/
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

+ 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