我使用下面的基本代码将文件从一个位置复制到另一个位置。
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打开。知道我为什么会犯这个错误吗?
编辑:所有文件都在网络驱动器上。路径示例:\\19549dabjnb0002\images\2017.07\11\A217081\20170711095405.pdf
发布于 2017-07-27 12:12:19
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
。
编辑:用于优化移动,只需使用这两条路径并将文件分别添加到其中。它将很容易地循环:
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
https://stackoverflow.com/questions/45350323
复制相似问题