Code:
Sub TestItmNmbrWSOfromPropName() ' https://www.excelfox.com/forum/showthread.php/2951-TestsExplorerWSO?p=23968&viewfull=1#post23968
' I want the Name property value. I can get it from GetDetailsOf(FldItm, 0) where FldItm is a windows shell object (WSO) folder item whose properties I am intersted in , and, as example, the 0 is the property item number, PropItmNmbr, that I have so far seen in any operating system for the property of the file or folder Name
MsgBox Prompt:=ItmNmbrWSOfromPropName("Name") ' German and English name property
MsgBox Prompt:=ItmNmbrWSOfromPropName("Größe") ' German size property
MsgBox Prompt:=ItmNmbrWSOfromPropName("Size") ' English size property https://eileenslounge.com/viewtopic.php?p=313847#p313847
MsgBox Prompt:=ItmNmbrWSOfromPropName("Dateiversion") ' German version property
MsgBox Prompt:=ItmNmbrWSOfromPropName("File version") ' English version property
End Sub
Public Function ItmNmbrWSOfromPropName(ByVal PropNme As String) As String
Dim PropItmNmbr As Long
'Dim objWSO As Shell32.Shell ' Early Binding ' Set objShell = New Shell32.Shell ' https://i.postimg.cc/Fz9zrnNm/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg https://i.postimg.cc/sDC9S54h/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpgDim objWSO As Object ' Late Binding
Dim objWSO As Object ' Late Binding
' Set objwso = New Shell32.Shell ' https://i.postimg.cc/Fz9zrnNm/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg https://i.postimg.cc/sDC9S54h/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg
Set objWSO = CreateObject("shell.application")
'Dim objWSOFolder As Shell32.Folder : Set objWSOFolder = objWSO.Namespace(Parf)
Dim objWSOFolder As Object: Set objWSOFolder = objWSO.Namespace(ThisWorkbook.Path & "") ' Any valid path will do objWSO.Namespace(Parf & "") ' & "" ' https://stackoverflow.com/questions/33868233/shell-namespace-not-accepting-string-variable-but-accepting-string-itself/77888851#77888851 https://microsoft.public.access.narkive.com/Jl55mts5/problem-using-shell-namespace-method-in-vba#post5
'Dim FldItm As Shell32.FolderItem
For PropItmNmbr = 0 To 400 Step 1
'If objWSOFolder.GetDetailsOf("You can put anything here. Null is fashionable, but anything will do, as long as it is not a valid WSO folder item object - see https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=Ugy_RiNN_kAqUvZ8W994AaABAg.9xhyRrsUUOM9zYlZPKdOpm", PropItmNmbr) = PropNme Then
If objWSOFolder.GetDetailsOf(Null, PropItmNmbr) = PropNme Then
Let ItmNmbrWSOfromPropName = PropItmNmbr ' Effectively fill the pseudo String variable ItmNmbrWSOfromPropName with the number you were looking for
Exit Function
Else
End If
Next PropItmNmbr
Let ItmNmbrWSOfromPropName = "Couldn't find the WSO property item number for a property with the name of " & PropNme ' ' Effectively fill the pseudo String variable ItmNmbrWSOfromPropName with a message if the WSO property name you gave could not be found for any og the numbers you looped ( 0 to 400 )
End Function
I don’t need super speed performance, so that solution would do. But I was thinking there might be some direct way with some existing method or similar which I have not been able to find yet, like pseudo something like this sort of form
Code:
Sub TestItmNmbrWSOfromPropNameS() ' https://www.excelfox.com/forum/showthread.php/2951-TestsExplorerWSO?p=23968&viewfull=1#post23968
' I want the Name property value. I can get it from GetDetailsOf(FldItm, 0) where FldItm is a windows shell object (WSO) folder item whose properties I am intersted in , and, as example, the 0 is the property item number, PropItmNmbr, that I have so far seen in any operating system for the property of the file or folder Name
Debug.Print "Name "; Tab(25); ItmNmbrWSOfromPropNameS("Name") ' German and English name property
Debug.Print "Size "; Tab(25); ItmNmbrWSOfromPropNameS("Größe, Size") ' German and English size property
Debug.Print "Version "; Tab(25); ItmNmbrWSOfromPropNameS("Dateiversion;File version") ' German and English version property
Debug.Print "Last modified date "; Tab(25); ItmNmbrWSOfromPropNameS("Geändert am, Date modified; Änderungsdatum") ' German and English date last modified property
Debug.Print "Created date "; Tab(25); ItmNmbrWSOfromPropNameS("Date created, Erstellt am, Erstelldatum") ' German and English datee created property
End Sub
' The next function adds the possibility of multiple name attempts for example if you have the property name in different languages. You can give a single name or several names which should be separated by a comma, a semi colon, or any number or spaces or a combination of spaces and a comma or a semi colon
' The function returns the property number and the name found, if successful
Public Function ItmNmbrWSOfromPropNameS(ByVal PropNme As String) As String
Let PropNme = Trim(PropNme) ' VBA Trim remove just leading and trailing sppaces
' Let PropNme = Replace(PropNme, " ", " ", 1, -1, vbBinaryCompare)
Let PropNme = Replace(PropNme, ";", " ", 1, -1, vbBinaryCompare)
Let PropNme = Replace(PropNme, ",", " ", 1, -1, vbBinaryCompare)
' Let PropNme = Application.Trim(PropNme) ' Remove all leading and trailing spaces, and all spaces more than one in between
Let PropNme = Replace(PropNme, " ", " ", 1, -1, vbBinaryCompare) ' 6 spaces to 2 spaces
Let PropNme = Replace(PropNme, " ", " ", 1, -1, vbBinaryCompare) ' 5 spaces to 2 spaces
Let PropNme = Replace(PropNme, " ", " ", 1, -1, vbBinaryCompare) ' 4 spaces to 2 spaces
Let PropNme = Replace(PropNme, " ", " ", 1, -1, vbBinaryCompare) ' 3 spaces to 2 spaces
Dim arrNms() As String: Let arrNms() = Split(PropNme, " ", -1, vbBinaryCompare)
Dim PropItmNmbr As Long
'Dim objWSO As Shell32.Shell ' Early Binding ' Set objShell = New Shell32.Shell ' https://i.postimg.cc/Fz9zrnNm/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg https://i.postimg.cc/sDC9S54h/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpgDim objWSO As Object ' Late Binding
Dim objWSO As Object ' Late Binding
' Set objwso = New Shell32.Shell ' https://i.postimg.cc/Fz9zrnNm/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg https://i.postimg.cc/sDC9S54h/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg
Set objWSO = CreateObject("shell.application")
'Dim objWSOFolder As Shell32.Folder : Set objWSOFolder = objWSO.Namespace(Parf)
Dim objWSOFolder As Object: Set objWSOFolder = objWSO.Namespace(ThisWorkbook.Path & "") ' Any valid path will do objWSO.Namespace(Parf & "") ' & "" ' https://stackoverflow.com/questions/33868233/shell-namespace-not-accepting-string-variable-but-accepting-string-itself/77888851#77888851 https://microsoft.public.access.narkive.com/Jl55mts5/problem-using-shell-namespace-method-in-vba#post5
'Dim FldItm As Shell32.FolderItem
For PropItmNmbr = 0 To 400 Step 1
Dim Cnt As Long
For Cnt = LBound(arrNms()) To UBound(arrNms())
'If objWSOFolder.GetDetailsOf("You can put anything here. Null is fashionable, but anything will do, as long as it is not a valid WSO folder item object - see https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=Ugy_RiNN_kAqUvZ8W994AaABAg.9xhyRrsUUOM9zYlZPKdOpm", PropItmNmbr) = PropNme Then
If objWSOFolder.GetDetailsOf(Null, PropItmNmbr) = arrNms(Cnt) Then
Let ItmNmbrWSOfromPropNameS = PropItmNmbr & " " & arrNms(Cnt) ' Effectively fill the pseudo String variable ItmNmbrWSOfromPropName with the number you were looking for
Exit Function
Else
End If
Next Cnt
Next PropItmNmbr
Let ItmNmbrWSOfromPropNameS = "Couldn't find the WSO property item number for a property with the name of " & PropNme ' ' Effectively fill the pseudo String variable ItmNmbrWSOfromPropName with a message if the WSO property name you gave could not be found for any of the numbers you looped ( 0 to 400 )
End Function
Bookmarks