运行时错误76:未findpath

我正在使用下面的基本代码将文件从一个位置复制到另一个位置。

Sub CopyFilesToLocation() Dim lRow As Long lRow = Cells(Rows.Count, 1).End(xlUp).Row For i = 69 To lRow FileCopy Cells(i, 19), "C:\Users\a222012\Desktop\Test\" & Cells(i, 9) & ".pdf" Next i End Sub 

单元格(i,19)包含指向pdf文件的超链接。 我有大约5000个文件。 使用On Error Resume Next帮助我通过运行时错误,并提取约4400个文件。 其余的600将全部提供运行时错误,而不会出现On Error Resume Next 。 这600个文件具有有效的链接,点击后,pdf将打开。 任何想法,为什么我会得到错误?

编辑:所有文件都在networking驱动器上。 path示例: \\19549dabjnb0002\images\2017.07\11\A217081\20170711095405.pdf

FileCopy的作品相当不错 。 尽量简化你的代码,然后从那里开始工作。 并删除On Error Resume Next 。 像这样的东西应该工作:

 Sub CopyFilesToLocation() Dim strPath As String strPath = "C:\Users\USER\Desktop\" & Cells(2, 1) Debug.Print Cells(1, 1) Debug.Print strPath Stop 'Take a look at the immediate window FileCopy Cells(1, 1), strPath End Sub 

当代码停止时,请看一下即时窗口Ctrl+G

编辑:为了优化移动,只需使用两个path,并分别添加文件。 它会很容易地循环:

 Option Explicit Public Sub TestMe() Dim strPathD As String 'Destination path Dim strPathL As String 'Location path strPathL = "C:\Users\USER\Desktop\" strPathD = "C:\Users\USER\Desktop\NewFolder\" FileCopy strPathL & Cells(1, 1), strPathD & Cells(1, 1) End Sub