メインコンテンツへスキップ

Excelのセルに複数のファイル名をインポートするにはどうすればよいですか?

数百のファイルを含むフォルダーがあり、これらのファイル名をワークシートのセルにインポートするとします。 XNUMXつずつコピーして貼り付けると、かなりの時間がかかります。この記事では、フォルダーからワークシートに複数のファイル名をインポートするのに役立ついくつかの簡単なトリックについて説明します。

VBAコードを使用して複数のファイル名をワークシートセルにインポートします

Kutools forExcelを使用して複数のファイル名をワークシートセルにインポートする


VBAコードを使用して複数のファイル名をワークシートセルにインポートします

次のVBAコードは、ファイル名、ファイル拡張子、フォルダー名をワークシートのセルにインポートするのに役立ちます。次の手順で実行してください。

1。 ファイル名をインポートする新しいワークシートを起動します。

2。 を押し続けます Alt + F11 キーを押して アプリケーション向け Microsoft Visual Basic 窓。

3に設定します。 OK をクリックします。 インセット > モジュール、次のコードをに貼り付けます モジュール 窓。

VBAコード:ワークシートのセルに複数のファイル名をインポートします

Sub GetFileList()
'updateby Extendoffice
    Dim xFSO As Object
    Dim xFolder As Object
    Dim xFile As Object
    Dim xFiDialog As FileDialog
    Dim xPath As String
    Dim i As Integer
    Set xFiDialog = Application.FileDialog(msoFileDialogFolderPicker)
    If xFiDialog.Show = -1 Then
        xPath = xFiDialog.SelectedItems(1)
    End If
    Set xFiDialog = Nothing
    If xPath = "" Then Exit Sub
    Set xFSO = CreateObject("Scripting.FileSystemObject")
    Set xFolder = xFSO.GetFolder(xPath)
    ActiveSheet.Cells(1, 1) = "Folder name"
    ActiveSheet.Cells(1, 2) = "File name"
    ActiveSheet.Cells(1, 3) = "File extension"
    i = 1
    For Each xFile In xFolder.Files
        i = i + 1
        ActiveSheet.Cells(i, 1) = xPath
        ActiveSheet.Cells(i, 2) = Left(xFile.Name, InStrRev(xFile.Name, ".") - 1)
        ActiveSheet.Cells(i, 3) = Mid(xFile.Name, InStrRev(xFile.Name, ".") + 1)
    Next
End Sub

4. 次に、 F5 キーを押してこのコードを実行し、ポップアウトされた[参照]ウィンドウで、ファイル名フォームをインポートするフォルダーを選択します。スクリーンショットを参照してください。

docインポートファイル名1

5。 そして、 OK ボタンをクリックすると、次の結果が得られます。

docインポートファイル名2

Note:特定のフォルダ内にサブフォルダがある場合、サブフォルダ内のファイル名はインポートされません。


Kutools forExcelを使用して複数のファイル名をワークシートセルにインポートする

フォルダとサブフォルダの両方にファイル名をインポートする必要がある場合は、心配しないでください。 Kutools for Excelさん ファイル名リスト ユーティリティを使用すると、サブフォルダを含む特定のフォルダ内のすべてのファイル名を簡単にインポートできます。

Kutools for Excel : 300以上の便利なExcelアドインがあり、30日以内に制限なしで無料で試すことができます. 

インストールした後 Kutools for Excel、次のようにしてください。

1に設定します。 OK をクリックします。 クツールズプラス> インポート・エクスポート > ファイル名リスト、スクリーンショットを参照してください:

2。 の中に ファイル名リスト ダイアログボックスで、次の操作を実行します。

(1.)クリック docインポートファイル名5 インポートしたいファイルのあるフォルダを選択するボタン。

(2.)チェック サブディレクトリにファイルを含める サブフォルダーのファイル名をインポートします。

(3.)インポートするファイルの種類を[ ファイルタイプ セクション;

(4.)表示するファイルサイズの単位をXNUMXつ選択します。 ファイルサイズ単位 セクション;

(5.)ファイル名とフォルダをハイパーリンクする場合は、チェックしてください。 ハイパーリンクを作成する オプションを選択します。

docインポートファイル名4

3。 設定終了後、をクリックしてください OK ボタンをクリックすると、次のスクリーンショットのように、フォルダとサブフォルダの両方のファイル名が新しいワークシートにインポートされます。

docインポートファイル名6

ヒント:特定のフォルダから指定されたタイプのファイル名をXNUMXつだけインポートする場合は、次のことを確認できます。 指定 内のオプション ファイル名リスト ダイアログでファイル拡張子を入力すると、指定したタイプのファイル名のみがフォルダーとサブフォルダーの両方からインポートされます。

このファイル名リスト機能の詳細については、クリックしてください…

今すぐExcel用のKutoolsをダウンロードして無料トライアル!


デモ:Kutools forExcelを使用して複数のファイル名をワークシートセルにインポートする

Kutools for Excel:300以上の便利なExcelアドインがあり、30日以内に制限なしで無料で試すことができます。 今すぐダウンロードして無料トライアル!

関連記事:

フォルダとサブフォルダ内のすべてのファイルをワークシートに一覧表示するにはどうすればよいですか?

フォルダ内のすべてのファイル名を一覧表示し、Excelでそれらのハイパーリンクを作成するにはどうすればよいですか?

最高のオフィス生産性向上ツール

🤖 Kutools AI アシスタント: 以下に基づいてデータ分析に革命をもたらします。 インテリジェントな実行   |  コードを生成  |  カスタム数式の作成  |  データを分析してグラフを生成する  |  Kutools関数を呼び出す...
人気の機能: 重複を検索、強調表示、または識別する   |  空白行を削除する   |  データを失わずに列またはセルを結合する   |   数式なしのラウンド ...
スーパールックアップ: 複数の基準の VLookup    複数の値の VLookup  |   複数のシートにわたる VLookup   |   ファジールックアップ ....
詳細ドロップダウン リスト: ドロップダウンリストを素早く作成する   |  依存関係のドロップダウン リスト   |  複数選択のドロップダウンリスト ....
列マネージャー: 特定の数の列を追加する  |  列の移動  |  Toggle 非表示列の表示ステータス  |  範囲と列の比較 ...
注目の機能: グリッドフォーカス   |  デザインビュー   |   ビッグフォーミュラバー    ワークブックとシートマネージャー   |  リソースライブラリ (自動テキスト)   |  日付ピッカー   |  ワークシートを組み合わせる   |  セルの暗号化/復号化    リストごとにメールを送信する   |  スーパーフィルター   |   特殊フィルター (太字/斜体/取り消し線をフィルター...) ...
上位 15 のツールセット12 テキスト ツール (テキストを追加, 文字を削除する、...)   |   50+ チャート 種類 (ガントチャート、...)   |   40+ 実用的 (誕生日に基づいて年齢を計算する、...)   |   19 挿入 ツール (QRコードを挿入, パスから画像を挿入、...)   |   12 変換 ツール (数字から言葉へ, 通貨の換算、...)   |   7 マージ&スプリット ツール (高度な結合行, 分割セル、...)   |   ... もっと

Kutools for Excel で Excel スキルを強化し、これまでにない効率を体験してください。 Kutools for Excelは、生産性を向上させ、時間を節約するための300以上の高度な機能を提供します。  最も必要な機能を入手するにはここをクリックしてください...

説明


Officeタブは、タブ付きのインターフェイスをOfficeにもたらし、作​​業をはるかに簡単にします

  • Word、Excel、PowerPointでタブ付きの編集と読み取りを有効にする、パブリッシャー、アクセス、Visioおよびプロジェクト。
  • 新しいウィンドウではなく、同じウィンドウの新しいタブで複数のドキュメントを開いて作成します。
  • 生産性を 50% 向上させ、毎日何百回もマウス クリックを減らすことができます!
Comments (14)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
very helpful. Tnx much
Rated 5 out of 5
This comment was minimized by the moderator on the site
Another easy method is there. Just copy the directory path where you have saved the documents, and paste that link in browser (chrome/mozilla). You will get the name list and just copy paste into excel. Cheers!
This comment was minimized by the moderator on the site
i want to add table,only folder name,and data modified as well?
This comment was minimized by the moderator on the site
Hello,
Do you want to list all folder names from a specific main folder? Please give your problem more detailed.
This comment was minimized by the moderator on the site
i want to mention only folder name.what is vba code for that.
This comment was minimized by the moderator on the site
is there a way to put the folder path already in the code?
This comment was minimized by the moderator on the site
For the VBA code, how would you pull in the date modified as well?
This comment was minimized by the moderator on the site
Hello,
Add the date modified column for the imported filenames, please apply the following VBA code, please try it, hope it can help you!

Sub GetFileList()
Dim xFSO As Object
Dim xFolder As Object
Dim xFile As Object
Dim xFiDialog As FileDialog
Dim xPath As String
Dim i As Integer
Set xFiDialog = Application.FileDialog(msoFileDialogFolderPicker)
If xFiDialog.Show = -1 Then
xPath = xFiDialog.SelectedItems(1)
End If
Set xFiDialog = Nothing
If xPath = "" Then Exit Sub
Set xFSO = CreateObject("Scripting.FileSystemObject")
Set xFolder = xFSO.GetFolder(xPath)
ActiveSheet.Cells(1, 1) = "Folder name"
ActiveSheet.Cells(1, 2) = "File name"
ActiveSheet.Cells(1, 3) = "File extension"
ActiveSheet.Cells(1, 4) = "Date last modified"
i = 1
For Each xFile In xFolder.Files
i = i + 1
ActiveSheet.Cells(i, 1) = xPath
ActiveSheet.Cells(i, 2) = Left(xFile.Name, InStrRev(xFile.Name, ".") - 1)
ActiveSheet.Cells(i, 3) = Mid(xFile.Name, InStrRev(xFile.Name, ".") + 1)
ActiveSheet.Cells(i, 4) = CDate(xFile.datelastmodified)
Next
End Sub
This comment was minimized by the moderator on the site
Thanks. It was awesome
This comment was minimized by the moderator on the site
saya coba yg pake vba di run bisa tapi pas di step browser nya bukan oke tapi open terus sampai ke file tertentu dan ketika di klik malah run time 26 path not found bisa bantu kenapa itu bisa terjadi?
This comment was minimized by the moderator on the site
Apakah bisa merename file dengan excel?
terimakasih sangat membantu perkerjaan saya,
This comment was minimized by the moderator on the site
Very helpful, thank you!
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations