The mapping of Property to Index is dependent on the OS, and sometimes the release of the OS (Win 10 just changed some)
I use the property name to find the index and the index with the file to get the value
This returns a MS Word doc as a type.
Writing to cells is left as an exercise to the reader
Option Explicit
Sub test()
' MsgBox FieldNumber("Type")
' MsgBox FieldNumber("Item Type")
MsgBox FileProperty(Environ("HOMEDRIVE") & Environ("HOMEPATH") & "\Desktop", "test.docx", "Type")
MsgBox FileProperty(Environ("HOMEDRIVE") & Environ("HOMEPATH") & "\Desktop", "test.docx", "Item Type")
End Sub
Function FileProperty(FilePath As String, FileName As String, PropName As String) As String
Dim objFolder As Object
Dim objFolderItem As Object
Dim objShell As Object
Dim i As Long
FileProperty = vbNullString
i = FieldNumber(PropName)
If i = -1 Then Exit Function
FileName = StrConv(FileName, vbUnicode)
FilePath = StrConv(FilePath, vbUnicode)
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(StrConv(FilePath, vbFromUnicode))
If Not objFolder Is Nothing Then
Set objFolderItem = objFolder.ParseName(StrConv(FileName, vbFromUnicode))
End If
If Not objFolderItem Is Nothing Then
FileProperty = objFolder.GetDetailsOf(objFolderItem, i)
Else
FileProperty = vbNullString
End If
Set objShell = Nothing
Set objFolder = Nothing
Set objFolderItem = Nothing
End Function
Private Function FieldNumber(s) As Long
Dim oFolder As Object
Dim n As Long
Dim sDesktop As Variant
s = UCase(s)
sDesktop = CreateObject("wscript.shell").specialfolders(10) & Application.PathSeparator
Set oFolder = CreateObject("shell.application").Namespace(sDesktop)
n = 0
On Error GoTo Oops
Do While True
If s Like UCase(oFolder.GetDetailsOf(oFolder.Items, n)) Then
FieldNumber = n
Exit Function
Else
n = n + 1
End If
If n > 1000 Then Exit Do
Loop
Oops:
Set oFolder = Nothing
FieldNumber = -1
End Function
'list all properties
Private Sub GetDetailsOfFields()
Dim objShell
Dim objFolder
Dim n As Long
Set objShell = CreateObject("shell.application")
Set objFolder = objShell.Namespace("C:\Users\Daddy\Desktop\")
On Error GoTo Oops
For n = 0 To 1000
Worksheets("FileProperties").Cells(n + 1, 1).Value = n
Worksheets("FileProperties").Cells(n + 1, 2).Value = objFolder.GetDetailsOf(objFolder.Items, n)
Next n
Oops:
Set objFolder = Nothing
Set objShell = Nothing
End Sub