LoginSignup
2
8

More than 5 years have passed since last update.

Excel VBAで一瞬でファイル一覧を作成する

Posted at

はじめに

Excelシートに、フォルダにあるファイル一覧表を一瞬で作成するマクロです。

手順

  1. Excelを起動して、開発-Visual Basicを選択する
  2. プロジェクト画面からSheet1を選択して、コードの画面を表示
  3. 次のコードをコピペする (\で表示されている箇所は、Windowsなので¥です。ご注意!)

Sub Syori()

Dim buf As String
Dim lCnt As Long
Dim Path As String

Path = "D:\C\Ruby"           '←ここはメンテナンスする

buf = Dir(Path & "\" & "*.*")
Do While buf <> ""
    lCnt = lCnt + 1
    Cells(lCnt, 1) = buf
    buf = Dir()
Loop

End Sub
4. 実行すると、このように、ファイルの一覧が取得ができました
image.png

2
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
8