Friday, 5 October 2012

How To Copy Day Task Files To Day Folder using Excel VBA Macro

Excel VBA Macro To Copy Daily Task Files To Respective Day Folder
'Day Folder Created Automatically
'How Does This Macro Works :
'For Example: There Different Files like TPR-03-JULY-2012.xlsx,SAS-03JULY-2012.Jpg,REDDY-03-JULY-2012.Docx
'When You Run This Macro It wil Create Folder as '03-JULY-2012' And Copy All Those Files to This Folder

Sub CopyDayFiles2DayFolder()
  
    Dim FromPath As String
    Dim ToPath As String
    
    Dim FSO As Object
    Dim File As Object
    
    Dim FName As String

    'Application.DisplayAlerts = False

    On Error Resume Next

    FromPath = "C:\Documents and Settings\Administrator\My Documents\"

    ToPath = "F:\"
     
    Set FSO = CreateObject("Scripting.FileSystemObject")

    If FSO.FolderExists(FromPath) = False Then


        MsgBox FromPath & " " & " Doesn't Exist"
        Exit Sub

    End If

    If FSO.FolderExists(ToPath) = False Then


        MsgBox ToPath & " " & " Doesn't Exist"
        Exit Sub

    End If
    
               
 For Each File In FSO.GetFolder(FromPath).Files
       
    FName = Left(Right(File.Name, 15), 11)
    
    If InStr(File.Name, FName) <> InStr(File.Name, FName) + 1 Then
    MkDir "F:\" & FName
    'File.Copy "F:\" & FName & "\"   ' To Copy
    File.Move "F:\" & FName & "\"    ' To Move
    End If

Next File

    MsgBox "Your Daily Task Files Has Been Copied To Respective Day Folders", 

    vbOKCancel, "Successfull Copied"        

End Sub

No comments:

Post a Comment

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts