VBAでフォルダ内ファイル一覧を作成する
E2~G2に変換先フォルダの入力セルを追加しました。
 
サブフォルダも含めフォルダ内のファイル一覧を作成するVBAです。
フォルダ内文字列カウントソフトの「
Step 2 サブフォルダも含めフォルダ内からファイルを検索する」を改造しました。
 
・VBEウィンドウの参照設定で「Microsoft Scrpting Runtime」を有効にしてください。
・取得したファイル名から、htmかhtmlの場合に表示します。
・変換フォルダ名を削除し表示します。
Sub ExFolderSearch(sSearchPath As String, lStartRow As Long, lStartCol As Long)
     Dim tFso As FileSystemObject
     
     Set tFso = New FileSystemObject
     Call ExFolderSearchSub(tFso.GetFolder(sSearchPath), lStartRow - 1, lStartCol)
     Set tFso = Nothing
 End Sub
 Private Sub ExFolderSearchSub(ByVal tPath As Folder, ByRef lRow As Long, ByVal lCol As Long)
    Dim tInPath As Folder
    Dim tFile As File
    
    For Each tInPath In tPath.SubFolders
        Call ExFolderSearchSub(tInPath, lRow, lCol)
    Next tInPath
    For Each tFile In tPath.Files
         If Right(LCase(tFile.Name), 4) = ".htm" Or Right(LCase(tFile.Name), 5) = ".html" Then
             lRow = lRow + 1
             Cells(lRow, lCol) = Mid(tPath.Path & "\", Len(Range("G2")) + 1, Len(tPath.Path & "\") _
                - Len(Range("G2"))) & tFile.Name
         End If
     Next tFile
     Set tPath = Nothing
 End Sub
実行結果です。
サブフォルダの場合はサブフォルダ名からの表示になっています。
