我有這個代碼,它成功地回傳了 0-5 個元資料項。但是,日期以美國和英國的混合格式回傳......我需要強制執行 Cdate 或類似的東西,以使日期全部讀為英國日期。(DD/MM/YY) 我通常使用 Cdate 做其他事情,但不確定如何讓它作業......
代碼:
Dim sFile As Object, obja
'Create Shell Object & NameSpace
Set oShell = CreateObject("Shell.Application")
Set oDir = oShell.Namespace("FILEPATH")
ActiveSheet.Cells.ClearContents
'Loop thru each File/Folder inside Root Directory
iRow = 1
For Each sFile In oDir.Items
iRow = iRow 1
'Loop thru Each Property
For i = 0 To 5
'Get File Property Name & Value
obja = oDir.GetDetailsOf(sFile, i)
If obja <> "" Then
iRow = iRow 1
'Enter File Property to Sheet
ActiveSheet.Range("A" & iRow) = oDir.GetDetailsOf(oDir, i)
ActiveSheet.Range("B" & iRow) = obja
End If
Next
Next
MsgBox "Process Completed"
End Sub
uj5u.com熱心網友回復:
對于日期屬性,將字串拆分為日、月、年、小時、分鐘,然后使用DateSerial()和重新創建日期TimeSerial()。
Option Explicit
Sub files()
Dim sFile As Object, obja, oShell, oDir
Dim iRow As Long, i As Long
Dim sValue, sName As String
Dim arDT, arDMY, arHMS, dt As Date
'Create Shell Object & NameSpace
Set oShell = CreateObject("Shell.Application")
Set oDir = oShell.Namespace("C:\temp\so\data")
ActiveSheet.Cells.ClearContents
'Loop thru each File/Folder inside Root Directory
iRow = 1
For Each sFile In oDir.Items
iRow = iRow 1
'Loop thru Each Property
For i = 0 To 5
sName = oDir.GetDetailsOf(oDir, i)
sValue = oDir.GetDetailsOf(sFile, i)
If sValue <> "" Then
iRow = iRow 1
Range("A" & iRow) = sName
If sName Like "Date*" Then
' sValue is dd/mm/yyyy hh:mm
arDT = Split(sValue, " ")
arDMY = Split(arDT(0), "/")
arHMS = Split(arDT(1), ":")
dt = DateSerial(arDMY(2), arDMY(1), arDMY(0)) _
TimeSerial(arHMS(0), arHMS(1), 0)
Range("B" & iRow).NumberFormat = "dd/mm/yy hh:mm"
Range("B" & iRow) = dt
Else
Range("B" & iRow) = sValue
End If
End If
Next
Next
MsgBox "Process Completed"
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/369561.html
上一篇:按降序排序圖表
