Home » 文章 » 电脑技术 » Excel » 按列表文件名分发文件

按列表文件名分发文件

按列表的文件名分发文件如何按列表的文件名分发文件呢?如下解决。

代码如下:

Sub GetFiles()
Dim fds, fd, folser1, folder2, fs, f, mypath$, myname$
Application.ScreenUpdating = False
Application.DisplayAlerts = False
‘mypath = Replace(ThisWorkbook.Path, “\需提取的文件夹\”, “”)
mypath = “D:\2016\”

Set Fso = CreateObject(“Scripting.FileSystemObject”)
Set Fso = New Scripting.FileSystemObject
Set folder1 = Fso.GetFolder(mypath) ‘获得文件夹
Set fds = folder1.Files ‘子文件夹集合
For r = 2 To Range(“B65536”).End(xlUp).Row()
For Each f In fds ‘遍历文件
If f.Name Like “*” & Cells(r, 2).Value & “*” Then
‘Debug.Print f.Name
Cells(r, 3) = “完成”
FileCopy mypath & “\” & f.Name, “D:\2016提取结果\” & f.Name
Else
‘Cells(r, 3) = “没找到匹配文件”
End If
Next
Next

Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

 

下载地址分发文件夹

微信 OR 支付宝 扫描二维码
为博主 打个赏
pay_weixinpay_zhifubao
金额随意 快来“打”我呀~

Leave a Reply

Your email address will not be published. Required fields are marked *

*