+ 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
    MS 365
    Posts
    532

    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
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    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
    MS 365
    Posts
    532

    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,636

    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)

Similar Threads

  1. [SOLVED] Excel VBA code for selecting a folder then search & open specified files in that folder
    By Excelrookie_1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-27-2021, 03:09 AM
  2. [SOLVED] VBA Code to save to a folder within a folder within a folder all based on cell values.
    By sintek in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-24-2016, 04:24 PM
  3. Replies: 2
    Last Post: 12-29-2015, 04:19 AM
  4. Open Folder (Prompt User for final folder name in location path)
    By synergeticink in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-21-2014, 03:33 PM
  5. Macros Open folder, copy, paste and close the folder
    By hahahahahahaha in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-10-2013, 05:03 PM
  6. [SOLVED] VBA Code open files in folder, copy text to workbook-Next time folder opened copy only new
    By Bikeman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-02-2013, 07:59 PM
  7. Replies: 1
    Last Post: 01-24-2006, 12:25 AM

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