检索元数据时在 VBA Excel 中强制执行 Cdate

Enforcing Cdate in VBA Excel when retrieving Meta Data

我有这段代码可以成功返回 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

对于日期属性,将字符串拆分为日、月、年、小时、分钟,然后使用 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