Sub MISCFile_Listing()
'Standard module code, like: Module1.
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&
'strFolderNm = CurDir
On Error Resume Next
Columns("B:C").Columns.Ungroup
ActiveSheet.Cells.Delete
ActiveSheet.Range("A4").Value = "Folder"
ActiveSheet.Range("b4").Value = "Name.Ext"
ActiveSheet.Range("c4").Value = "Author"
ActiveSheet.Range("d4").Value = "Lines"
ActiveSheet.Range("e4").Value = "Amount"
ActiveSheet.Range("f4").Value = "Year"
ActiveSheet.Range("g4").Value = "Create Date"
ActiveSheet.Range("H4").Value = "Last Modified"
ActiveSheet.Range("I4").Value = "Size"
ActiveSheet.Range("J4").Value = "Units"
ActiveSheet.Range("K4").Value = "Type"
ActiveSheet.Range("L4").Value = "Attribute"
ActiveSheet.Range("A4:L4").Font.Bold = True
Set objFileScript = CreateObject("Scripting.FileSystemObject")
'Change Path as Needed
Set objFolder = objFileScript.GetFolder("Y:\Budget\2009\Manual Sheets\Manual Sheets\Plant Projects & MISC\Posted")
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.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Select
Selection.Value = strFilePath
Selection.Offset(0, 1).Value = strFileNm
Selection.Offset(0, 2).Formula = "='" _
& Left(strFilePath, InStrRev(strFilePath, Application.PathSeparator)) _
& "[" & strFileNm & "]BUDGET'!$N$2"
Selection.Offset(0, 3).Formula = "='" _
& Left(strFilePath, InStrRev(strFilePath, Application.PathSeparator)) _
& "[" & strFileNm & "]BUDGET'!$C$2"
Selection.Offset(0, 4).Formula = "='" _
& Left(strFilePath, InStrRev(strFilePath, Application.PathSeparator)) _
& "[" & strFileNm & "]BUDGET'!$V$3"
Selection.Offset(0, 5).Formula = "='" _
& Left(strFilePath, InStrRev(strFilePath, Application.PathSeparator)) _
& "[" & strFileNm & "]BUDGET'!$C$3"
Selection.Offset(0, 6).Value = strFileCreate
Selection.Offset(0, 7).Value = strFileDtMod
Selection.Offset(0, 8).Value = Format(dubFileSize, "###,###,###")
Selection.Offset(0, 9).Value = " Bytes"
Selection.Offset(0, 10).Value = strFileType
Selection.Offset(0, 11).Value = strFileAttr
On Error Resume Next
Next objThisFile
Columns("A:m").Columns.AutoFit
Columns("A:A").Insert Shift:=xlToRight
Range("A4").FormulaR1C1 = "File Name - Link"
Range("A4").Font.Bold = True
Range("A5").FormulaR1C1 = "=HYPERLINK(RC2,RC3)"
On Error Resume Next
Range("A5").AutoFill Destination:=Range("A5:A" & Range("B" & Rows.Count).End(xlUp).Row), Type:=xlFillDefault
Columns("B:C").Columns.Group
ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=1
With ActiveSheet.Range("A1")
.Value = "Posted Manual Sheet Inventory - Plant Projects & MISC"
.Font.Bold = True
End With
With ActiveSheet.Range("A2")
.FormulaR1C1 = "As of " & Date
.Font.Bold = True
End With
Columns("A:A").Columns.AutoFit
With Range("A4:M4")
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlDouble
End With
With Columns("D:G")
.Value = .Value
End With
Columns("F:F").NumberFormat = "#,##0_);[Red](#,##0)"
Columns("E:E").HorizontalAlignment = xlCenter
Columns("G:G").NumberFormat = "0_);(0)"
Columns("H:I").NumberFormat = "mm/dd/yy;@"
Columns("J:J").NumberFormat = "#,##0_);[Red](#,##0)"
Dim rng2 As Range
Dim lastrow As Long
Dim cc As Range
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Set rng2 = Range(Cells(5, 4), Cells(lastrow, 7))
For Each cc In rng2
If cc.Value = "#REF!" Or cc.Value = "0" Then cc.Value = ""
Next cc
Application.Goto reference:="R1C1"
MsgBox ("MISC Inventory Complete")
End Sub