excel - 如果 Excel 文件中存在该文件的名称,如何将文件从一个位置复制到另一个位置
问题描述
我有一个包含图像文件名称的 Excel 文件。在同一个文件夹中,我有 Excel 文件中列出的所有图像以及一些附加图像。现在我要做的是分离 Excel 文件中列出的所有图像。Excel 文件中列出的图像应复制到另一个文件夹。我已按照本文作者的指示使用了该方法:
https://www.extendoffice.com/documents/excel/4775-move-files-based-on-excel-list.html
Sub movefiles()
'Updateby Extendoffice
Dim xRg As Range, xCell As Range
Dim xSFileDlg As FileDialog, xDFileDlg As FileDialog
Dim xSPathStr As Variant, xDPathStr As Variant
Dim xVal As String
On Error Resume Next
Set xRg = Application.InputBox("Please select the file names:", "KuTools For Excel", ActiveWindow.RangeSelection.Address, , , , , 8)
If xRg Is Nothing Then Exit Sub
Set xSFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
xSFileDlg.Title = " Please select the original folder:"
If xSFileDlg.Show <> -1 Then Exit Sub
xSPathStr = xSFileDlg.SelectedItems.Item(1) & "\"
Set xDFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
xDFileDlg.Title = " Please select the destination folder:"
If xDFileDlg.Show <> -1 Then Exit Sub
xDPathStr = xDFileDlg.SelectedItems.Item(1) & "\"
For Each xCell In xRg
xVal = xCell.Value
If TypeName(xVal) = "String" And xVal <> "" Then
FileCopy xSPathStr & xVal, xDPathStr & xVal
Kill xSPathStr & xVal
End If
Next
End Sub
但是当我执行代码时没有任何反应。有什么方法可以完成任务吗?
解决方案
推荐阅读
- python - 使用 python 执行命令行脚本时找不到“__main__”模块
- java - Spring Webflux - 抛出检查的自定义异常(不是 RuntimeException)的正确方法
- java - 在 Postman 上测试时,GraphQL 查询语法错误。SpringBoot 服务器
- python - Seaborn 不断为多图翻转我的行
- javascript - 实时生成动态“视频”,输入数据?
- python - Python中的自定义聚合函数
- c++ - 当 BIO 不受套接字支持时,何时在使用诸如“SSL_connect()”之类的 OpenSSL 调用时正确刷新缓冲区?
- regex - Haskell 正则表达式的行为不同:
- javascript - 如何在 ReactJS 中将数据 yyyy-mm-dd 转换为 dd/mm/yyyy?
- swift - Swift 错误代码:实例成员 'getStory' 不能用于类型 'StoryBrain';你的意思是使用这种类型的值吗?