ファイルの作成日に週番号と曜日名があり、セルH7とN7の値と一致するフォルダ内のすべてのファイルを一覧表示しようとしています。vba excel - ファイル作成日が週番号と曜日の名前と一致するフォルダ内のファイルを一覧表示しますか?
例えば私のフォルダには、次のファイルが含まれています
1.PDF (Created 16/12/2016)
2.PDF (Created 01/12/2016)
3.PDF (Created 16/12/2016)
マイセルH7は(12月15日には下に落ちるだろう)週番号50を含んでいます。
私のセル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に土曜日に置けば、それは金曜日の日付のファイルを一覧表示し、正常に動作するようには思えません。
また、金曜日の日付のファイルだけでなく、すべてのファイルがリストされています。
私が間違っている場所を誰かに見せてもらえますか?
おかげ