0
我想列出文件創建日期的文件夾中的所有文件的週數和星期幾名稱與單元格H7和N7中的值匹配。vba excel - 列出文件創建日期與周編號和星期幾名稱相匹配的文件夾中的文件?
例如我的文件夾中包含下列文件:
1.PDF (Created 16/12/2016)
2.PDF (Created 01/12/2016)
3.PDF (Created 16/12/2016)
我的手機H7包含星期數50(12月15日將在下降)。
我的手機N7包含星期五的星期五(這將匹配12月16日)。
我使用的代碼如下:
Sub Example1()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
If Dir("G:\STOCK\(3) Promotions\Allocations\" & Range("T7").Value & "\" & client, vbDirectory) <> "" Then
Set objFolder = objFSO.GetFolder("G:\STOCK\(3) Promotions\Allocations\" & Range("T7").Value & "\")
'Utilize Adv Day = False
If Range("N7").Value <> "" Then
i = 1
'loops through each file in the directory and prints their names and path
For Each objFile In objFolder.Files
If DatePart("ww", objFile.DateCreated, vbMonday, vbFirstFourDays) = Range("H7").Value And WeekdayName(Weekday(objFile.DateCreated)) = Range("N7").Value Then
'print file PG
Cells(i + 12, 1) = Range("T7").Value
'print file Month
Cells(i + 12, 5) = Range("H7").Value
'print file Year
Cells(i + 12, 9) = Range("B7").Value
'print file name
Cells(i + 12, 13) = objFile.Name
'print file path
Cells(i + 12, 18) = "=hyperlink(""" & objFile.Path & """)"
i = i + 1
End If
Next objFile
Else
MsgBox "No Results Found."
End If
End If
End Sub
的代碼似乎並沒有正常工作,如果我把在週六進入細胞N7則列出了星期五的日期的文件。
此外代碼列出了所有文件,而不僅僅是那些星期五的日期文件。
請有人能告訴我我要去哪裏嗎?
感謝