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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Macro in Excel

  • 31-10-2009 6: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