指定フォルダ内ファイル一覧取得

Sub GetFilesInFolder()
    Dim folderPath As String
    Dim files() As String
    Dim fileCount As Integer
    Dim fileName As String
    Dim i As Integer
    
    ' フォルダパスを指定
    folderPath = "C:\Path\To\Your\Folder"
    
    ' 指定フォルダ内の全てのファイルを取得
    files = GetAllFilesInFolder(folderPath)
    
    ' ファイル数を取得
    fileCount = UBound(files)
    
    ' プルダウンにファイル一覧を追加
    With Sheet1.Range("A1").Validation
        .Delete ' 既存のデータ検証を削除
        .Add Type:=xlValidateList, Formula1:=Join(files, ",")
        .InCellDropdown = True
    End With

End Sub