ファイル内の.txtファイルのファイル名を別々のフォルダにリストアップしようとしています(sample picture) 以下のコードは、うまく機能しますが、特定のサブフォルダや配置は含まれていませんフォルダヘッダーの列。サブフォルダ内のファイル名を一覧表示する
誰かがここで正しい方向に向けることができますか?
だから、Option Explicit
Sub GetFileNames()
Dim xRow As Long
Dim xDirect$, xFname$, InitialFoldr$
InitialFoldr$ = "C:\main folder dir\"
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = Application.DefaultFilePath & "\"
.Title = "Please select a folder to list Files from"
.InitialFileName = InitialFoldr$
.Show
If .SelectedItems.Count <> 0 Then
xDirect$ = .SelectedItems(1) & "\"
xFname$ = Dir(xDirect$, 7)
Do While xFname$ <> ""
ActiveCell.Offset(xRow) = xFname$
xRow = xRow + 1
xFname$ = Dir
Loop
End If
End With
End Sub
:
Subfoldername1 | Subfoldername2
-------------- | --------------
Textfile1 | Textfile3
Textfile2 | Textfile4
サブサブフォルダがある場合は何? – WhatsThePoint