CreateObject - Namespace variable
Alan,
I think the problem is that you are not assigning a value to your
strFolderPath variable before the "Set objFolder =
objShell.Namespace(strFolderPath)" line of code.
I would also declare your variable.
Maybe something like this:
Public Sub getattributes(strFolderPath As String)
Dim arrHeaders(40)
Dim strFolderPath As String
strFolderPath = "C:\My Documents"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(strFolderPath)
For i = 0 To 39
arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
Range("A1").Select
ActiveCell.Offset(0, i) = arrHeaders(i)
Next
ActiveCell(2, 1).Select
For Each strFileName In objFolder.Items
For i = 0 To 39
ActiveCell.Offset(0, i) =
objFolder.GetDetailsOf(strFileName, i)
Next
ActiveCell.Offset(1, 0).Select
Next
End Sub
HTH,
Conan Kelly
"Alan" wrote in message
...
I think i have managed to cobble a bit of code together that will allow me
to
get all file attributes from all files with a folder... however I would
seek
to call this routine for every folde in a directory and as a result I am
seeking to use a string variable for the objShell.Namespace declaration...
However I get errors
Run time error 91 ... Object Variable or withblock variable unset
If I enter a single directory string in place of the variable "C:\My
Documents" it works fine ??
My Code is
Public Sub getattributes(strFolderPath As String)
Dim arrHeaders(40)
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(strFolderPath)
For i = 0 To 39
arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
Range("A1").Select
ActiveCell.Offset(0, i) = arrHeaders(i)
Next
ActiveCell(2, 1).Select
For Each strFileName In objFolder.Items
For i = 0 To 39
ActiveCell.Offset(0, i) = objFolder.GetDetailsOf(strFileName, i)
Next
ActiveCell.Offset(1, 0).Select
Next
End Sub
Any help with this variable or a way round this would be appreciated
Regards
|