728x90

윈도우의 특정 폴더로 파일을 전체 Move 하기 위한 것이며, 다른 PC에서 작업한 사항을 반영하기 위해서 이미 Move된 것인지 파악하여 처리하는 코드이다.


Sub files_move()
    Dim rngC, rngAll As Range
    Dim oldName, newName As String
    Dim k%, r%
   
    Application.ScreenUpdating = False
    Application.DisplayStatusBar = True
    Set rngAll = Range([A2], Cells(Rows.Count, "A").End(3))
   
    For Each rngC In rngAll
        If InStr(Cells(rngC.Row, "A"), "원본") > 0 Then  '// 원본 폴더로 되어 있으면
            Application.StatusBar = rngC.Row & " 행 진행중"
            oldName = Left(Cells(rngC.Row, "A"), Len(Cells(rngC.Row, "A")) - 3) & "\" & Cells(rngC.Row, "B")
            newName = Cells(rngC.Row, "A") & "\" & Cells(rngC.Row, "B")
           
            If Dir(oldName, vbDirectory) = "" Then  '// 파일이 없다면
                If Dir(newName, vbDirectory) <> Empty Then
                    Cells(rngC.Row, "C").Value = "Moved"
                    Cells(rngC.Row, "C").Interior.ColorIndex = 36
                    k = k + 1
                End If
               
            Else
                If Dir(newName, vbDirectory) = Empty Then   '// 원본폴더에 파일이 없다면
                    Name oldName As newName
                    Cells(rngC.Row, "C").Value = "Moved"
                    Cells(rngC.Row, "C").Interior.ColorIndex = 36
                    r = r + 1
                Else
                    k = k + 1
                    Debug.Print rngC.Row & " 행은 이미 Moved 상태입니다"
                End If
            End If
           
        End If
    Next rngC
    Application.StatusBar = r & " 건 Moved  " & k & " Already Moved"
End Sub

블로그 이미지

Link2Me

,