EDITAR:
OK. Ainda não é possível calcular com precisão por que o caso 2 não funciona, mas descobri que a maneira "correta" de obter o objeto FolderItem correspondente a strFile (conforme exigido por .GetDetailsOf() ) é usar o método .ParseName() :
Function GetTags(ByVal strFile As String)
Const csFile As String = "MyTestFile.xlsx"
Dim i As Integer
With CreateObject("Shell.Application").Namespace("C:\Users\XXXX\Documents\Safe Space\MacroTest\")
GetTags = .GetDetailsOf(.ParseName(strFile)), 18)
End With
End Function
Eu não posso explicar por que ele não funciona, mas eu tenho três soluções possíveis.
1) Use CStr(strFile) em vez de strFile ao chamar .GetDetailsOf() :
Function GetTags(ByVal strFile As String)
Const csFile As String = "MyTestFile.xlsx"
Dim i As Integer
With CreateObject("Shell.Application").Namespace("C:\Users\XXXX\Documents\Safe Space\MacroTest\")
GetTags = .GetDetailsOf(.Items.Item(CStr(strFile)), 18)
End With
End Function
ou
2) Altere o tipo de parâmetro de strFile para Variant :
Function GetTags(ByVal strFile As Variant)
Const csFile As String = "MyTestFile.xlsx"
Dim i As Integer
With CreateObject("Shell.Application").Namespace("C:\Users\XXXX\Documents\Safe Space\MacroTest\")
GetTags = .GetDetailsOf(.Items.Item("" & strFile), 18)
End With
End Function
ou
3) Concatene uma string nula para strFile ao chamar .GetDetailsOf() :
Function GetTags(ByVal strFile As Variant)
Const csFile As String = "MyTestFile.xlsx"
Dim i As Integer
With CreateObject("Shell.Application").Namespace("C:\Users\XXXX\Documents\Safe Space\MacroTest\")
GetTags = .GetDetailsOf(.Items.Item("" & strFile), 18)
End With
End Function