Hi Norman Martens1,
Welcome to the Microsoft community.
The error you're encountering, "Method 'NameSpace' of object 'IShellDispatch6' failed," typically indicates that the strPath variable being passed to the Namespace method either does not represent a valid directory path or there's an issue with the way paths are handled, especially when dealing with special characters or unconventional paths.
I refine the Get_Extended_File_Info function to better handle potential path issues and debug the process. I'll add error handling to identify any problematic paths and ensure paths are formatted correctly before passing them to the Shell object:
Function Get_Extended_File_Info(strPath As Variant, strFile As String, Optional PropNum As Integer = 3) As String
' Length of video
Dim sFile, oDir, obja As Object
Dim strValidPath As String
' Ensure the path ends with a backslash if it doesn't already
If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
' Debugging: Check if the path exists before attempting to create Shell object
If Not FolderExists(strPath) Then
MsgBox "The path '" & strPath & "' does not exist.", vbCritical, "Invalid Path"
Get_Extended_File_Info = "Error: Path Not Found"
Exit Function
End If
' Attempt to Create Shell Object & NameSpace with proper error handling
On Error Resume Next
Set oDir = CreateObject("Shell.Application").Namespace(strPath)
If Err.Number <> 0 Then
MsgBox "Error accessing the path '" & strPath & "'. Error: " & Err.Description, vbCritical, "Shell Namespace Error"
Err.Clear
Get_Extended_File_Info = "Error: Access Denied or Invalid Path"
Exit Function
End If
On Error GoTo 0
' Continue as before...
Set sFile = oDir.ParseName(strFile)
obja = oDir.GetDetailsOf(sFile, PropNum)
If obja <> "" Then
obja = Replace(obja, ChrW(8206), "")
obja = Replace(obja, ChrW(8207), "")
Get_Extended_File_Info = obja
Else
Get_Extended_File_Info = "N/A"
End If
Set oDir = Nothing
End Function
' Helper Function to check if a folder exists
Function FolderExists(path As String) As Boolean
FolderExists = Dir(path, vbDirectory) <> ""
End Function
In the updated code, I've added:
- Path Validation: Ensuring the path ends with a backslash to avoid path resolution issues.
- Debugging Message: A message box alerts users when the specified path doesn't exist, which could be the source of the error.
- Error Handling: Around the creation of the Shell object to catch any exceptions and provide a more informative error message.
With these modifications, you should be able to identify if the problem lies in the path being invalid or inaccessible to the Shell object. I recommend to test different paths to further isolate the issue, ensuring they are accessible and correctly formatted.
Please feel free to tell if these code help.
Best Regards,
Jonathan Z - MSFT | Microsoft Community Support Specialist