0
我有一個執行並創建PDF文件的宏。每次運行宏時,都會生成PDF。我想將報告的最後一個版本(每天運行三次)移至文件夾標題「過去的報告」。我一直在玩下面的腳本,但它不適合我。活動報告文件夾只包含最新創建的PDF。將生成的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
你可以刪除'On Error GoTo nextIt'並檢查錯誤? –
你想用'sSourceFile = PDFPath&Dir(PDFPath&「* .pdf」)''得到什麼?因爲如果你打印出'sSourceFile',它只會返回'「D:\ #### \ Pinging Program \ Active Report \」' –
@VictorMoraes - 'sSourceFile = PDFPath&Dir(PDFPath&「* .pdf」) '將'sSourceFile'設置爲'PDFPath'目錄中第一個.pdf文件的名稱(包括路徑)。 (如果該目錄中有** no **'.pdf'文件,那麼它將只返回與「PDFPath」相同的值,但如果該目錄中至少有一個.pdf文件,它將返回預計。) – YowE3K