Attribute VB_Name = "Module2"
Public myRows As Long
'
'指定したフォルダのファイル名、サイズ、パス名をExcelファイルに書き出す
'
'
'
Sub GetFolderAttrib()

    Dim myFolder As String
    Dim newFolder, newName
    Dim Fs As FileSystemObject
    Dim objfolder As Object
    Dim myExcel As Object

    Set Fs = New FileSystemObject
    myFolder = "C:\ProgramData\Autodesk\RVT 2023\Family Templates"
    
    Set objfolder = Fs.GetFolder(myFolder)
    Set myExcel = Worksheets("Sheet1")

    myExcel.Cells(1, 1).ColumnWidth = 15
    myExcel.Cells(1, 2).ColumnWidth = 10
    myExcel.Cells(1, 3).ColumnWidth = 35
    myExcel.Cells(1, 4).ColumnWidth = 35
    myExcel.Cells(1, 5).ColumnWidth = 10

    myExcel.Cells(1, 1).Value = "ファイル名"
    myExcel.Cells(1, 2).Value = "サイズ"
    myExcel.Cells(1, 3).Value = "パス"
    myExcel.Cells(1, 4).Value = "Folder"
    myExcel.Cells(1, 5).Value = "Type"

    myRows = 2

    Call checkFile(myExcel, objfolder)

    MsgBox ("終了")

End Sub

'
' サブフォルダ以下を再帰的に処理を行う
'
Sub checkFile(myExcel As Object, objfolder As Object)

    Dim objFile As Object
    Dim objSubFolder As Object

    For Each objFile In objfolder.Files
        myExcel.Cells(myRows, 1).Value = objFile.Name
        myExcel.Cells(myRows, 2).Value = objFile.Size
        myExcel.Cells(myRows, 3).Value = objFile.path
        myExcel.Cells(myRows, 4).Value = objFile.ParentFolder
        myExcel.Cells(myRows, 5).Value = objFile.Type
        
        DoEvents
        
        myRows = myRows + 1
        'myExcel.Cells(myRows, 1).Select
    Next

    For Each objSubFolder In objfolder.SubFolders
        Call checkFile(myExcel, objSubFolder)
    Next

End Sub

