Friday, 5 October 2012

How To Copy Different Types [.txt,.xlsx,.docx,.pptx] of Files To Respective Type Folder

Excel VBA Macro To Copy Different Types [.txt,.xlsx,.docx,.pptx] of Files To Respective Type Folder

'This Macro  Copies or Moves Different Type[.txt,.xlsx,.docx,.pptx]of Files To Respective Type Folder
'The Each Type Folder Automatically Created For Each Type Of Files In The Same Path

Sub CopyDiffTypeFiles2TypeFolder()
  
    Dim FromPath As String
       
    Dim FSO As Object
    Dim File As Object
    
    Dim FileExt As String

Application.DisplayAlerts = False
On Error Resume Next

    FromPath = "C:\Documents and Settings\Administrator\My Documents\"
        
    Set FSO = CreateObject("Scripting.FileSystemObject")
               
For Each File In FSO.GetFolder(FromPath).Files
      
    FileExt = Right(File.Name, 4)
    
    If InStr(File.Name, FileExt) <> InStr(File.Name, FileExt) + 1 Then
    
    MkDir FromPath & "MyFiles_" & FileExt
    File.Copy FromPath & FileExt & "\"   ' To Copy
    'File.MoveFromPath & FileExt & "\"   ' To Move

    End If

    
Next File

    MsgBox "Your Diff. Type of Task Files Copied/Moved To Respective Type Folders",    
    vbOKCancel,  "Successfull Copied/Moved"

End Sub

No comments:

Post a Comment

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts