Results 1 to 2 of 2

How to Move specific files to folders with VBA

Threaded View

EnzioL How to Move specific files to... 05-09-2012, 05:31 AM
JBeaucaire Re: How to Move specific... 05-09-2012, 06:46 AM
  1. #1
    Registered User
    Join Date
    05-03-2012
    Location
    World
    MS-Off Ver
    Excel 2010
    Posts
    7

    How to Move specific files to folders with VBA

    Hello all,

    I would like to move files from a specifice folder to several different folders with VBA.

    The files i like to move are stored in a specific folder on C:\Material

    The folder contains different kind of excel files that needs to be moved to different folders each month.

    The beginning of the file name is always the same for each separate file but the month changes.

    I have a listed the file names in excel and also the folder where to move.


    Filen Name Location Correct Folder
    AA MARCH 2012.XLS C:\Material C:\AA
    BB MARCH 2012.XLS C:\Material C:\BB

    Look for filename in A1 in excel sheet - Then look for it in C:\Material If found then Move to C:\AA
    Then Goto next row in excel sheet A2 look for filename - Then if found in C:\Material then move to C:\BB
    End Function


    I ripped one from the internet:

    
    Sub CopyFilesFolder2Folder()
    Dim fso
    Dim sfol As String, dfol As String
    sfol = "c:\material" ' source folder path
    dfol = "C:\destination" ' match the destination in column D1??
    Set fso = CreateObject("Scripting.FileSystemObject")
    On Error Resume Next
    If Not fso.FolderExists(sfol) Then
    ****MsgBox sfol & " is not a valid folder/path.", vbInformation, "Invalid Source"
    ElseIf Not fso.FolderExists(dfol) Then
    ****MsgBox dfol & " is not a valid folder/path.", vbInformation, "Invalid Destination"
    Else
    ****fso.CopyFile (sfol & "\*.*"), dfol '  HOW to change to the file name in excel sheet B1??
    End If
    If Err.Number = 53 Then MsgBox "File not found"
    End Sub
    Last edited by EnzioL; 05-09-2012 at 05:47 AM.

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