将生成的PDF移动到networking驱动器上的新文件夹

我有一个macros执行并创build一个PDF文件。 每次运行macros时,都会生成一个PDF。 我想将报告的最后一个版本(每天运行三次)移动到文件夹标题“过去的报告”。 我一直在玩下面的脚本,但它不适合我。 活动报告文件夹只包含最近创build的PDF。

谁能提供帮助? 如果需要,很高兴添加更多信息。

Public Sub transferFile() On Error GoTo nextIt Set fileSystemObject = CreateObject("Scripting.FileSystemObject") PDFPath = "D:\####\Pinging Program\Active Report\" pastPDFPath = "D:\####\Pinging Program\Past Reports" sSourceFile = PDFPath & Dir(PDFPath & "*.pdf") sDestinationFile = "D:\####\Pinging Program\Past Reports" 'move file If Dir(sSourceFile) <> "" Then fileSystemObject.moveFile sSourceFile, sDestinationFile End If nextIt: End Sub 

您的目标文件夹缺less最后的斜线。 此外,作为未来的build议,如果您不像Victor所说的那样绕过error handling,错误会更容易理解。 你的代码如下所示:

 Public Sub transferFile() Set fileSystemObject = CreateObject("Scripting.FileSystemObject") PDFPath = "C:\test\Active Report\" pastPDFPath = "C:\test\Past Reports" sSourceFile = PDFPath & Dir(PDFPath & "*.pdf") sDestinationFile = "C:\test\Past Reports\" 'move file If Dir(sSourceFile) <> "" Then fileSystemObject.moveFile sSourceFile, sDestinationFile End If End Sub 

我已经testing过它,它按预期工作。 问候,