|
本帖最后由 zjdh 于 2022-11-22 09:40 编辑
我这运行很正常,不知你那啥地方出问题了,请将宏中第一句注销,再运行一下看报错在哪一句。
Sub 复制()
'On Error Resume Next
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "请选择被扫描文件目录:"
.Show
If .SelectedItems.Count <> 0 Then
sTemp = .SelectedItems(1) & "\"
Range("D1") = sTemp
End If
End With
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "请选择存放文件目录:"
.Show
If .SelectedItems.Count <> 0 Then
CopyPath = .SelectedItems(1) & "\"
Range("D2") = CopyPath
End If
End With
Sfile = Dir(sTemp & "\*.*")
Range("B2:B65536").ClearContents
Do Until Sfile = ""
For I = 2 To Range("A65536").End(3).Row
If Split(Sfile, ".")(0) = Trim(Cells(I, 1).Value) Then
FileCopy sTemp & Sfile, CopyPath & Sfile '复制文件
Cells(65536, 2).End(3)(2) = Split(Sfile, ".")(0) '记录
Exit For
End If
Next
Sfile = Dir
Loop
End Sub |
|