【发布时间】:2021-11-12 19:41:33
【问题描述】:
我有一个程序会在文件夹中查找特定文件,如果存在,它将将该文件复制到指定的文件路径中。我想更进一步,采用我当前的代码并在它之前进行检查。此检查将查看指定文件夹并确定它的最后修改日期是否与今天的日期匹配。如果指定文件夹的最后修改日期与当前日期匹配,我希望代码进入该文件夹,然后执行当前代码。
Sub sbCopyingAFile()
'Declare Variables
Dim FSO
Dim sFile As String
Dim sSFolder As String
Dim sDFolder As String
'This is Your File Name which you want to Copy
sFile = "testfile.xlsx"
'Change to match the source folder path
sSFolder = "C:\Dropbox (###)\BD SQL\"
'Change to match the destination folder path
sDFolder = "C:\Dropbox (###)\BD SQL\testpath\"
'Create Object
Set FSO = CreateObject("Scripting.FileSystemObject")
'Checking If File Is Located in the Source Folder
If Not FSO.FileExists(sSFolder & sFile) Then
MsgBox "Specified File Not Found", vbInformation, "Not Found"
'Copying If the Same File is Not Located in the Destination Folder
ElseIf Not FSO.FileExists(sDFolder & sFile) Then
FSO.CopyFile (sSFolder & sFile), sDFolder, True
MsgBox "Specified File Copied Successfully", vbInformation, "Done!"
Else
MsgBox "Specified File Already Exists In The Destination Folder", vbExclamation, "File Already Exists"
End If
Debug.Print (sSFolder & sFile)
End Sub
【问题讨论】:
标签: vba