Chào các bạn,
Mình có 1 đoạn code như ở dưới. Mục đích của đoạn code là tìm kiếm những file có đuôi ".doc" trong các sub-folder(nằm trong folder lớn tên là Input) và copy tên subfolder chứa các file .doc sang Output folder. Mình chưa tìm kiếm và lọc được các folder chứa .doc. Các ACE cho em giải pháp để xử lý được ko ạ?
Cảm ơn mọi người
Sub Copy_Folder()
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FielExt As String
FromPath = "C:\Users\HOA-PC\Desktop\Test\Input" 'Co chua nhieu sub-folder
ToPath = "C:\Users\HOA-PC\Desktop\Test\Output" '
FielExt = "*.doc" ' tim kiem cac file co duoi la .doc
' Kiem tra su ton tai cua "" o sau duong dan
If Right(FromPath, 1) = "" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If
If Right(ToPath, 1) = "" Then
ToPath = Left(ToPath, Len(ToPath) - 1)
End If
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " khong ton tai"
Exit Sub
End If
FSO.CopyFolder Source:=FromPath, Destination:=ToPath
MsgBox "File cua ban da duoc copy"
End Sub
Mình có 1 đoạn code như ở dưới. Mục đích của đoạn code là tìm kiếm những file có đuôi ".doc" trong các sub-folder(nằm trong folder lớn tên là Input) và copy tên subfolder chứa các file .doc sang Output folder. Mình chưa tìm kiếm và lọc được các folder chứa .doc. Các ACE cho em giải pháp để xử lý được ko ạ?
Cảm ơn mọi người

Sub Copy_Folder()
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FielExt As String
FromPath = "C:\Users\HOA-PC\Desktop\Test\Input" 'Co chua nhieu sub-folder
ToPath = "C:\Users\HOA-PC\Desktop\Test\Output" '
FielExt = "*.doc" ' tim kiem cac file co duoi la .doc
' Kiem tra su ton tai cua "" o sau duong dan
If Right(FromPath, 1) = "" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If
If Right(ToPath, 1) = "" Then
ToPath = Left(ToPath, Len(ToPath) - 1)
End If
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " khong ton tai"
Exit Sub
End If
FSO.CopyFolder Source:=FromPath, Destination:=ToPath
MsgBox "File cua ban da duoc copy"
End Sub