ファイル名を取得できたら便利ですよね。
以下のコードで可能です。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 | Sub test()     Dim file_path As Variant     file_path = Application.GetOpenFilename(MultiSelect:=True)     Dim i As Long     For i = 1 To UBound(file_path)         Cells(i, 1).Value = file_path(i)     Next End Sub | 
これを実行すると以下のようになります。
もしフルパスではなく、ファイル名のみを取得したい場合は以下のコードにします。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | Sub test2()     Dim file_path As Variant     file_path = Application.GetOpenFilename(MultiSelect:=True)     Dim i As Long     Dim pos As Long     Dim file_name As String     For i = 1 To UBound(file_path)         pos = InStrRev(file_path(i), "\")         file_name = Mid(file_path(i), pos + 1)         Cells(i, 1).Value = file_name     Next End Sub | 
これを実行すると以下のようになります。
ファイル名だけ取得できていますね!
ぜひご活用ください。ではまた。
 
  
  
  
  

コメント