Sub CopyFilesBasedOnCriteria()Dim fso As ObjectDim sourceFolder As StringDim destinationFolder As String' 设置源文件夹路径和目标文件夹路径sourceFolder = "C:\\test\\全波段模拟_Nimbostratus cloud - 副本"destinationFolder = "C:\\Desktop\\MOD02数据提取\\test\\52101"' 创建 FileSystemObject 对象Set fso = CreateObject("Scripting.FileSystemObject")' 复制文件fso.CopyFile sourceFolder & "\View=30_高程=4.5.jpg", destinationFolder & "\View=30_高程=4.5.jpg"fso.CopyFile sourceFolder & "\View=30_高程=4.jpg", destinationFolder & "\View=30_高程=4.jpg"fso.CopyFile sourceFolder & "\View=5_高程.jpg", destinationFolder & "\View=5_高程.jpg"' 释放 FileSystemObject 对象Set fso = Nothing
End Sub
背景:在一个文件夹下有上万个数据文档;
问题:想要根据特定的文件名提取数据,并将其复制到新的文件夹下;
解决办法:打开EXCEL文档,按“ALT+F11"跳出VBA后端,复制上述代码,点击运行
缺点:上述代码只能将所有得文件名依次列出,没能实现通过代码读取一列得文件名而直接将所求数据文档复制到新文件下。