将文件移动到另一个目录 [英] Moving files to another directory
本文介绍了将文件移动到另一个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将一列中的几千个文档移动到另一列中列出的文件夹中,然后再将其移动到未移动的第三列中(将会是文件不存在的错误.
I am trying to move several thousand documents from a list in one column and then move them to the folders listed in the other column, and then finally a third column with what has been moved and what hasn't (there will be errors where the file doesn't exist.
我知道如何逐个文件地进行操作,如下所示:
I know how to do it on a file by file basis as below:
我如何在整个专栏中做到这一点?
How do I do it for the whole columns though?
Sub Copy_One_File()
FileCopy "C:\Users\Ron\SourceFolder\Test.xls", "C:\Users\Ron\DestFolder\Test.xls"
End Sub
Sub Move_Rename_One_File()
'You can change the path and file name
Name "C:\Users\Ron\SourceFolder\Test.xls" As "C:\Users\Ron\DestFolder\TestNew.xls"
End Sub
推荐答案
如果这3列是"A","B"和"C"列,则此代码可能应该起作用.
If these 3 columns are columns "A", "B" and "C", this code should probably work.
Sub move_files()
Dim i As Long
With ActiveSheet
For i = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
Err.Clear
On Error Resume Next
Name (.Cells(i, 1)) As .Cells(i, 2) & "\" & StrReverse(Split(StrReverse(.Cells(i, 1)), "\")(0))
If Err = 0 Then .Cells(i, 3) = "YES" Else .Cells(i, 3) = "NO"
On Error GoTo 0
Next
End With
End Sub
这篇关于将文件移动到另一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文