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
'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
--------------------------------------------------------------------------------------------------------
Thanks, TAMATAM ; Business Intelligence & Analytics Professional
--------------------------------------------------------------------------------------------------------
No comments:
Post a Comment
Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.