2017-07-27 4 views
0

Windowsエクスプローラを使用して、VBAで選択したファイルの名前またはパスを表示したいとします。ListBoxに選択したファイルのパスを表示

これまで私が行ってきたことは、エクスプローラを開き、ファイルを選択することができますが、ファイルの名前/パスが表示されません。ここで

Private Sub CommandButton1_Click() 
    Dim fd As Office.FileDialog 
    Set fd = Application.FileDialog(msoFileDialogFilePicker) 
    With fd 
     .AllowMultiSelect = True 
     .Title = "Please select the file." 
     .Filters.Clear 
     .Filters.Add "All Files", "*.*" 

     If .Show = True Then 
     /// 
     ///here comes the part with showing the names in ListBox 
     /// 
     End If 
    End With 
End Sub 

答えて

0

が完成したコードです:

Public Sub CommandButton1_Click() 
    Dim i As Integer 

    Dim fd As Office.FileDialog 
    Set fd = Application.FileDialog(msoFileDialogFilePicker) 

    With fd 
     .AllowMultiSelect = True 
     .Title = "Please select the file." 
     .Filters.Clear 
     .Filters.Add "All Files", "*.*" 

     If .Show = True Then 
     For i = 1 To fd.SelectedItems.Count 
      ListBox1.AddItem fd.SelectedItems(i) 
     Next 
     End If 
    End With 
End Sub 
+0

ありがとうございました!正確に私が探していたもの:) –

関連する問題