[B]Public strFolderNm$[/B]
[COLOR=black][B]Sub File_Listing()[/B][/COLOR]
[COLOR=darkgreen]'Standard module code, like: Module1.[/COLOR]
Dim objFileScript As Object, objFolder As Object, objThisFile As Object, objThisFolder
Dim strFileCreate$, strFileAccess$, strFileDtMod$, strAttrNm$
Dim strFileNm$, strFileType$, strFileAttr$, strFilePath$
Dim dubFileSize#
Dim lngAttr&
[COLOR=navy]Call[/COLOR] mySelectFolderOnly
[COLOR=darkgreen]'strFolderNm = CurDir[/COLOR]
ActiveSheet.Columns("A:H").Delete Shift:=xlToLeft
ActiveSheet.Range("A1").Select
Selection.Value = "Folder"
Selection.Offset(0, 1).Value = "Name.Ext"
Selection.Offset(0, 2).Value = "Size"
Selection.Offset(0, 3).Value = "Units"
Selection.Offset(0, 4).Value = "Type"
Selection.Offset(0, 5).Value = "Created"
Selection.Offset(0, 6).Value = "Last Access"
Selection.Offset(0, 7).Value = "Last Modified"
Selection.Offset(0, 8).Value = "Attribute"
ActiveSheet.Range("A1:I1").Font.Bold = True
Set objFileScript = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFileScript.GetFolder(strFolderNm)
Set objThisFolder = objFolder.Files
For Each objThisFile In objThisFolder
strFilePath = objThisFile.Path
strFileNm = objThisFile.Name
dubFileSize = objThisFile.Size
strFileType = objThisFile.Type
strFileCreate = objThisFile.DateCreated
strFileAccess = objThisFile.DateLastAccessed
strFileDtMod = objThisFile.DateLastModified
strAttrNm = ""
lngAttr = 0
lngAttr = objThisFile.Attributes
If lngAttr = 0 Then
strAttrNm = strAttrNm & "Normal"
ElseIf lngAttr = 16 Then
strAttrNm = strAttrNm & "Directory "
ElseIf lngAttr = 1 Then
strAttrNm = strAttrNm & "Read-Only "
ElseIf lngAttr = 2 Then
strAttrNm = strAttrNm & "Hidden "
ElseIf lngAttr = 4 Then
strAttrNm = strAttrNm & "Normal System "
ElseIf lngAttr = 8 Then
strAttrNm = strAttrNm & "Volume "
ElseIf lngAttr = 32 Then
strAttrNm = strAttrNm & "Archive "
ElseIf lngAttr = 1024 Then
strAttrNm = strAttrNm & "Alias "
ElseIf lngAttr = 2048 Then
strAttrNm = strAttrNm & "Compressed "
Else
strAttrNm = strAttrNm & "Hidden System "
End If
strFileAttr = strAttrNm
ActiveSheet.Range("A65536").End(xlUp).Offset(1, 0).Select
Selection.Value = strFilePath
Selection.Offset(0, 1).Value = strFileNm
Selection.Offset(0, 2).Value = Format(dubFileSize, "###,###,###")
Selection.Offset(0, 3).Value = " Bytes"
Selection.Offset(0, 4).Value = strFileType
Selection.Offset(0, 5).Value = strFileCreate
Selection.Offset(0, 6).Value = strFileAccess
Selection.Offset(0, 7).Value = strFileDtMod
Selection.Offset(0, 8).Value = strFileAttr
Next objThisFile
ShowSubFolders objFileScript.GetFolder(strFolderNm)
Columns("A:H").Columns.AutoFit
[B]End Sub[/B]
[B]Private Sub mySelectFolderOnly()[/B]
[COLOR=darkgreen]'Standard module code, like: Module1.[/COLOR]
Dim strMyDrive$, strFilePath$
Application.DisplayAlerts = False
On Error GoTo myError
[COLOR=darkgreen]'Display Folder Shell, for you to select your Folder!
'(a,b,c,d)= b==> "Title"
'(a,b,c,d)= d==> 17=AllFilesDeskTop(MyComputer), 0=Root(DeskTop), 18=Network, 19=NetHood,
'23=Common(Programs), 2=Top(Programs), 38=All(Programs), 33=cookies, 16=DeskTop, 6=Favorites,
'5=MyDocuments, 4=Printers&Faxs, 27=PrintHood, 32=TempInterNet, 8=Recent,
'11=StartMenu, 7=StartUp(Only), 21=Templates, 36=Windows , 39=MyPictures,
'5=Personal(MyDocuments)[/COLOR]
[COLOR=#006400][/COLOR]
Set objFolder = CreateObject("Shell.Application"). _
BrowseForFolder(0, "Select the Folder to use!", 0, 17)
If Not objFolder Is Nothing Then
If Len(objFolder.Items.Item.Path) > 3 Then
strFolderNm = objFolder.Items.Item.Path & Application.PathSeparator
Else
strFolderNm = objFolder.Items.Item.Path
End If
End If
[COLOR=darkgreen]'Cancel Dialog then Exit![/COLOR]
If strFolderNm = "" Then GoTo myEnd
[COLOR=darkgreen]'Hold your selected Folder!
'ChDir strFolderNm
'strFilePath = strFolderNm[/COLOR]
[COLOR=darkgreen]'Work with selected folder.
'MsgBox strFilePath
[/COLOR]Exit Sub
[COLOR=darkgreen]'On error Display error information and help!
[/COLOR]myError:
MsgBox "On ""OK"" will Exit you back to your sheet!" & vbCr & vbCr & _
"Error Source: " & Err.Source & vbCr & _
"Error Number: " & Err.Number & vbCr & _
"Error Type: " & Err.Description & vbCr _
, vbMsgBoxHelpButton _
, "Error Accessing, " & strFilePath & ", Drive: " & strMyDrive _
, Err.HelpFile _
, Err.HelpContext
GoTo myEnd
myEnd:
[B]End Sub[/B]
[B]Sub myClearDisplay()[/B]
[COLOR=darkgreen]'Standard module code, like: Module1.[/COLOR]
[COLOR=#006400][/COLOR]
ActiveSheet.Columns("A:H").Delete Shift:=xlToLeft
ActiveSheet.Range("A1").Select
End Sub
[B]Sub ShowSubFolders(Folder)[/B]
For Each Subfolder In Folder.SubFolders
Set objFileScript = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFileScript.GetFolder(Subfolder.Path)
Set objThisFolder = objFolder.Files
For Each objThisFile In objThisFolder
strFilePath = objThisFile.Path
strFileNm = objThisFile.Name
dubFileSize = objThisFile.Size
strFileType = objThisFile.Type
strFileCreate = objThisFile.DateCreated
strFileAccess = objThisFile.DateLastAccessed
strFileDtMod = objThisFile.DateLastModified
strAttrNm = ""
lngAttr = 0
lngAttr = objThisFile.Attributes
If lngAttr = 0 Then
strAttrNm = strAttrNm & "Normal"
ElseIf lngAttr = 16 Then
strAttrNm = strAttrNm & "Directory "
ElseIf lngAttr = 1 Then
strAttrNm = strAttrNm & "Read-Only "
ElseIf lngAttr = 2 Then
strAttrNm = strAttrNm & "Hidden "
ElseIf lngAttr = 4 Then
strAttrNm = strAttrNm & "Normal System "
ElseIf lngAttr = 8 Then
strAttrNm = strAttrNm & "Volume "
ElseIf lngAttr = 32 Then
strAttrNm = strAttrNm & "Archive "
ElseIf lngAttr = 1024 Then
strAttrNm = strAttrNm & "Alias "
ElseIf lngAttr = 2048 Then
strAttrNm = strAttrNm & "Compressed "
Else
strAttrNm = strAttrNm & "Hidden System "
End If
strFileAttr = strAttrNm
ActiveSheet.Range("A65536").End(xlUp).Offset(1, 0).Select
Selection.Value = strFilePath
Selection.Offset(0, 1).Value = strFileNm
Selection.Offset(0, 2).Value = Format(dubFileSize, "###,###,###")
Selection.Offset(0, 3).Value = " Bytes"
Selection.Offset(0, 4).Value = strFileType
Selection.Offset(0, 5).Value = strFileCreate
Selection.Offset(0, 6).Value = strFileAccess
Selection.Offset(0, 7).Value = strFileDtMod
Selection.Offset(0, 8).Value = strFileAttr
Next objThisFile
Next
[B]End Sub[/B]