Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Macro in Excel

Options
  • 31-10-2009 7:54pm
    #1
    Registered Users 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 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