Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Oct 2014
    Posts
    6
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Help!! (Macro) Move Specific Files from one folder to another using a list

    I have a macro that will only move the first file listed using a list of numbers. These files start with numbers and have randoms names after ex: 1456_rabbit, 1987_pig. my list only contains numbers and it will only move the first one. Can anyone figure what is wrong with this macro? I attached this excel workbook with the macro.
    Attached Files Attached Files
    Last edited by hescobe; 2014-10-04 at 11:14.

  2. #2
    New Lounger
    Join Date
    Oct 2014
    Posts
    6
    Thanks
    5
    Thanked 0 Times in 0 Posts
    the file that has 24.0kb is the right one, I had the edit the macro for it to work. The first file doesnt do anything the second file moves the first on the list.

  3. #3
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Hescobe,

    Welcome to the Lounge as a new poster!

    I'm not sure why your current code won't run, although it could have something to do with the "1. Live" in the from path. However, I'm not up on the File System Object and will have to do some research (I'm currently traveling and will do that when I get back home).

    In the meantime here's code I have tested and does what I think you want.
    Code:
    Option Explicit
    
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    
    Sub Move_Files()
    
       Dim FromDir As String
       Dim ToDir As String
       Dim clubCol As Integer
       Dim currentRow As Integer
       Dim FromPath As String
       Dim zSourceFile As String
       Dim iRetCd As Long
       
       FromDir = ActiveWorkbook.Sheets("Sheet1").Range("C4").Value
       ToDir = ActiveWorkbook.Sheets("Sheet1").Range("C5").Value
    
       If Right(FromDir, 1) <> "\" Then
         FromDir = FromDir & "\"
       End If
        
       If Right(ToDir, 1) <> "\" Then
         ToDir = ToDir & "\"
       End If
        
       currentRow = Range("startRow").Row
       clubCol = Range("startRow").Column
        
        
       Do While Cells(currentRow, clubCol) <> 0
         zSourceFile = FromDir & Cells(currentRow, clubCol) & "_*.*"
         If Dir(zSourceFile) <> "" Then
           iRetCd = Shell(Environ$("comspec") & " /c move """ & zSourceFile & """ """ & ToDir & """")
           Sleep 10
           Cells(currentRow, clubCol + 1) = IIf(iRetCd > 0, "Success", "Failure!")
         Else
           Cells(currentRow, clubCol + 1) = "No Files: Failure!"
         End If
            
         currentRow = currentRow + 1
            
       Loop
        
    End Sub
    Results.JPG
    Results2.JPG

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  4. The Following User Says Thank You to RetiredGeek For This Useful Post:

    hescobe (2014-10-06)

  5. #4
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,640
    Thanks
    115
    Thanked 651 Times in 593 Posts
    Hescobe,

    Try changing the the line in your code from:

    Fnames = Dir(FromDir & FExtension)

    to

    Fnames = FromDir & FExtension

    HTH,
    Maud

  6. The Following User Says Thank You to Maudibe For This Useful Post:

    hescobe (2014-10-06)

  7. #5
    New Lounger
    Join Date
    Oct 2014
    Posts
    6
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Thank yall so much, yall are awsome!!

Tags for this Thread

Posting Permissions

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