Results 1 to 5 of 5

Macro to loop through all files in a folder

Threaded View

  1. #1
    Registered User
    Join Date
    11-23-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    10

    Macro to loop through all files in a folder

    Hi,

    I have a macro that I use to copy and paste data from a number of reports and I am trying to create a loop that will run the macro on all the files in a certain folder. I have had a go at it but the code I have just opens the first file in the folder that I have selected over and over again. So I'm looking for the code to only open each file once and then move on. Any help would be much appreciated!

    Sub Copy()
    
    ChDrive "X:\"
    ChDir "X:\Business \ Reports\"
    FileToOpen = Application.GetOpenFilename
    Do While FileToOpen <> ""
    If FileToOpen <> False Then
    Workbooks.Open (FileToOpen)
    
    Rest of Macro
    
    Else
    Exit Sub
    End If
    Loop
    End Sub
    Last edited by arlu1201; 02-26-2013 at 09:18 AM. Reason: Code tags instead of HTML tags.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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