【发布时间】:2021-06-07 00:57:05
【问题描述】:
我想从源文件夹复制 pdf 并且必须粘贴到基于 Excel 的 destpath 中,帮我解决我哪里出错了
Sub CheckandSend()
Dim irow As Integer
Dim DestPath As String
Dim SourcePath As String
Dim pfile As String
Dim FSO As Object
Dim Fldr As Object, f As Object
SourcePath = "I:\Mechanical\ExternalProjects\Cummins Emission Systems\35101124 PT Cup Test Rig\16 PDF to Vendor"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Fldr = FSO.GetFolder(SourcePath).Files
DestPath = "P:\CENTRAL PLANNING\PROJECTS 2020-2021\VAM-TARSON\Newfolder1"
irow = 7
Do While Cells(irow, 2) <> Empty
pfile = Dir(SourcePath & "\*" & Cells(irow, 2) & "*")
If pfile <> "" And Right(pfile, 3) = "PDF" Then
FileCopy SourcePath, DestPath
irow = irow + 1
End If
Loop
end sub
【问题讨论】:
-
SourcePath必须以反斜杠结尾。 -
那个也试过了,没有改善
-
@ArunKumarG。您的问题中没有错误描述。什么地方出了错?你得到了什么错误,在哪里?在复制到目标文件夹之前确保目标文件夹存在。
-
请注意
FileCopy SourcePath, DestPath中只有路径SourcePath但没有提到文件,因此它无法知道要复制哪个文件。你需要一个文件名附加到你的SourcePath。 -
FileCopy SourcePath, DestPath ,我如何将文件名(pfile)添加到 Sourcepath 中,导致我的文件名(pfile)在每个循环中都不同