Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This should do the trick. The first subroutine is the event that is triggered on the user clicking on a cell. Change the row and column numbers in the first <code>if</code> statement to change the target cell. You can put all of this code in the code module for the worksheet you want it to work on.</p> <pre><code>Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim filenames() As String Dim filename As Variant Dim filelist As String ' Make sure the user clicked our target cell If Target.Row = 2 And Target.Column = 2 Then ' Get a list of filenames filenames = GetFileNames ' Make sure we got some filenames If UBound(filenames) &gt; 0 Then ' Go through the filenames, adding each to the output string For Each filename In filenames filelist = filelist &amp; CStr(filename) &amp; "|" Next filename ' Remove the final delimiter filelist = Left(filelist, Len(filelist) - 2) ' Apply the output string to the target cell (adding another ' delimiter if there is already text in there) If Not Target.Value = "" Then Target.Value = Target.Value &amp; "|" End If Target.Value = Target.Value &amp; filelist End If End If End Sub </code></pre> <p>The following function is that which is called to open the file dialogue and retrieve the filenames.</p> <pre><code>Private Function GetFileNames() As String() Dim dlg As FileDialog Dim filenames() As String Dim i As Integer ' Open a file dialogue Set dlg = Application.FileDialog(msoFileDialogFilePicker) With dlg .ButtonName = "Select" ' Text of select/open button .AllowMultiSelect = True ' Allows more than one file to be selected .Filters.Add "All Files", "*.*", 1 ' File filter .Title = "Select file(s)" ' Title of dialogue .InitialView = msoFileDialogViewDetails .Show ' Redimension the array with the required number of filenames ReDim filenames(.SelectedItems.Count) ' Add each retrieved filename to the array For i = 1 To .SelectedItems.Count filenames(i - 1) = .SelectedItems(i) Next i End With ' Clean up and return the array Set dlg = Nothing GetFileNames = filenames End Function </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload