+ Reply to Thread
Results 1 to 4 of 4

Moving data files from one directory to another

Hybrid View

  1. #1
    Registered User
    Join Date
    09-01-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007
    Posts
    2

    Moving data files from one directory to another

    Need to find a macro that can read data in columns in my Excel document ( which lists file names ) and move files from one directory to another. Any ideas?

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Moving data files from one directory to another

    Something like this to get you started:

    Option Explicit
    
    Sub MoveFiles()
    Dim myPath As String, myDest As String
    Dim MyFiles As Range, aFile As Range
    
    myPath = "C:\Path\To\My\Files\"         'remember the \ at the end
    myDest = "C:\Path\To\Put\My\Files\"     'remember the \ at the end
    
    Set MyFiles = Sheets("Sheet1").Range("A:A").SpecialCells(xlConstants)
    
    For Each aFile In MyFiles               'evaluate one filename at a time
        If Len(Dir(myPath & aFile.Value)) > 0 Then      'make sure file exists
            Name myPath & aFile.Value As myDest & aFile.Value
            aFile.Offset(, 1).Value = "Moved"
        Else
            aFile.Offset(, 1).Value = "Not Found"
        End If
    Next aFile
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    09-01-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007
    Posts
    2

    Thumbs up Re: Moving data files from one directory to another

    Thank you. This is perfect!

  4. #4
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Moving data files from one directory to another

    @ ernies111

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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