Results 1 to 3 of 3

Thread: Trying to form a loop to open up files in other folders
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Jun 2019
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Trying to form a loop to open up files in other folders

    Hi,

    I am new to Excel VBA and am still on the learning curve, hopefully one of you can help!

    I am trying to form a loop that will run through a list of excel files that I have hard coded in column C. They need to open up one at a time, run the macro in that file, copy data on one of the sheets, paste it in my master workbook, close out, and then open up the next and do the same thing. The files are all in separate folders as well which makes it tougher. Also I plan on adding new file names to column C in the future.

    The part I am really struggling to get my head around is how I can open up the excel files that I have hard coded in column C one at a time. Once I can pull them up I'm sure I can figure out the rest.

    I have done some extensive googling but there is not much on this type of loop, from what I have found.

    Thanks!

  2. #2
    Board Regular
    Join Date
    May 2013
    Posts
    654
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Trying to form a loop to open up files in other folders

    I would walk through the range.?

    Something like below. Where I have Debug.Print you would put the rest of the code for your process.
    This is just to show one method.

    Don't forget. the macro recorder can generate a lot of code to help you as well.

    HTH
    Code:
    Sub TestRng()
    Dim rngFiles As Range, rng As Range
    
    
    Set rngFiles = Range("D2:D5")
    For Each rng In rngFiles
        Debug.Print rng.Value
    Next
    
    
    Set rng = Nothing
    End Sub
    Last edited by welshgasman; Jun 17th, 2019 at 05:15 PM.
    Office 2007
    Access novice. Sometimes trying to give something back

  3. #3
    New Member
    Join Date
    Jun 2019
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Trying to form a loop to open up files in other folders

    Thanks! I'll play around with it

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •