Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is similar to Sid's, just lets you double click any single cell to open the file dialog.</p> <p><em>In a Module</em></p> <p><img src="https://i.stack.imgur.com/wJNkT.png" alt="image showing where to paste the getList code"></p> <pre><code>Public Function getList(Optional ByVal Target As Range = Nothing) As String Dim Dialog As FileDialog Dim File As Integer Dim Index As Integer Dim List() As String Dim Item As Integer Dim Skip As Boolean Set Dialog = Application.FileDialog(msoFileDialogFilePicker) File = Dialog.Show If File = -1 Then ' Get a list of any pre-existing files and clear the cell If Not Target Is Nothing Then List = Split(Target.Value, "|") Target.Value = "" End If ' Loop through all selected files, checking them against any pre-existing ones to prevent duplicates For Index = 1 To Dialog.SelectedItems.Count Skip = False For Item = LBound(List) To UBound(List) If List(Item) = Dialog.SelectedItems(Index) Then Skip = True Exit For End If Next Item If Skip = False Then If Result = "" Then Result = Dialog.SelectedItems(Index) Else Result = Result &amp; "|" &amp; Dialog.SelectedItems(Index) End If End If Next Index ' Loop through the pre-existing files and add them to the result For Item = UBound(List) To LBound(List) Step -1 If Not List(Item) = "" Then If Result = "" Then Result = List(Item) Else Result = List(Item) &amp; "|" &amp; Result End If End If Next Item Set Dialog = Nothing ' Set the target output if specified If Not Target Is Nothing Then Target.Value = Result End If ' Return the string result getList = Result End If End Function </code></pre> <p><em>In Your Worksheet's Code</em></p> <p><img src="https://i.stack.imgur.com/Fk69q.png" alt="image showing where to paste the sheet code"></p> <pre><code>Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) If Target.Rows.Count = 1 And Target.Columns.Count = 1 Then getList Target End Sub </code></pre> <p><strong>Update</strong> I've changed the getList function (it wasn't broken, just made it do more) <ul></p> <li>It will allow you to double click any cell, which will open a file dialog.</li> <li>You can select 1 (or more) files</li> <li>The file names will be joined with the "|" character and put in the target cell</li> <li>If any pre-existing files are in the cell, the new ones will be appended to them</li> </ul> <p>It does not however support pressing enter to open the file dialog, you must double-click the cell.</p> <p><strong>Update</strong> To help VMO (commenter)</p> <p>The code in the worksheet module:</p> <pre><code>Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) If Target.Rows.Count = 1 And Target.Columns.Count = 1 Then If Target.Address = "$A$1" Then ' See Notes Below Target.Value = getList(Target) End If End If End Sub </code></pre> <p>To restrict what cell(s) are double-click'able you will need to use something like that. You can change <code>$A$1</code> to whatever you want or find a way to determine the target range's name (not too difficult)</p> <p>If your worksheet is not locked the cell that is clicked will keep focus, and be in edit-mode which is a little annoying. Locking the cell, in previous versions of excel fixed this (i think it doesn't work in v.2010+ though)</p> <p>The code in the module (getList) can remain almost exactly the same (although you might want to remove all the code that deals with multiple files, not required though). All you need to do is add one line of code.</p> <pre><code>....... Dim Skip As Boolean Set Dialog = Application.FileDialog(msoFileDialogFilePicker) Dialog.AllowMultiSelect = False ' This will restrict the dialogue to a single result File = Dialog.Show If File = -1 Then ...... </code></pre> <p>Hope this helps and I've understood what you were asking!</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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