Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Macro in Excel

  • 31-10-2009 06:54PM
    #1
    Registered Users, Registered Users 2 Posts: 929 ✭✭✭


    Im looking to import multiple xml files all called the same thing from different folders. I have code working for importing files from the same folder "September Orders" but there are loads of other of folders in that folder with files i need. Here is the code:
    Sub AllFolderFiles()
        Dim wb As Workbook
        Dim TheFile As String
        Dim MyPath As String
        MyPath = "C:\Users\xxxxxx\Desktop\September Orders"
        ChDir MyPath
        TheFile = Dir("infoXML.xml")
        Do While TheFile <> ""
            Set wb = Workbooks.Open(MyPath & "\" & TheFile)
            TheFile = Dir
         Loop
    End Sub
    


Comments

  • Registered Users, Registered Users 2 Posts: 38 DaveyByrne


    It's been years since I've programmed VB6, but here's an idea.

    Create an array of strings containing your directory names, like:

    myarray[0] = "November Orders"
    myarray[1] = "December Orders"

    Then in your loop, use the counter to index the value that's in the array:

    for i = 0 to 100
    MyPath = "C:\Users\xxxx\Desktop\" & myarray
    ' Then open the file and do whatever you want with it
    next

    Sorry the code is inaccurate, but I've not done VB6 in years... I moved to Dot Net ages ago. I hope you get my idea anyway.


Advertisement