Double click cell browse for file and paste path

drop05

Active Member
Joined
Mar 23, 2021
Messages
285
Office Version
  1. 365
Platform
  1. Windows
Hi, i wanted to see if there is a way to double click a cell in a range, allow the user to browse for a file and select it, not open it, but get the file path and paste the file path in the cell next to the cell double clicking
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
How are your VBA coding skills?

Create a double_click event for the Sheet where you want this to be implemented.

The following code does nothing, but it does display the file dialog box. This should give you a start on implementing what you need.

VBA Code:
Option Explicit

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  If Target(1, 1).Address = "$A$4" Then
    FileDialog
  End If
End Sub

Private Function FileDialog() As String
 
'Requires reference to Microsoft Office 12.0 Object Library.
 
   Dim fDialog As Office.FileDialog
   Dim varFile As Variant
 
 
   'Set up the File Dialog.
   Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
   With fDialog
      'Do not allow user to make multiple selections in dialog box.
      .AllowMultiSelect = False
             
      'Set the title of the dialog box.
      .Title = "Please select one or more files"
 
      'Clear out the current filters, and add our own.
      .Filters.Clear
      .Filters.Add "Access Databases", "*.XL*"  'edit for desired file types
      .Filters.Add "All Files", "*.*"
 
      If .Show = True Then
        'add code here for what to do with selected file name
      Else
         MsgBox "You clicked Cancel in the file dialog box."
      End If
   End With
End Function
 
Upvote 0
Paste the following in the Sheet level module :

VBA Code:
Option Explicit

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim DialogBox As FileDialog
Dim FileType

Dim path As String

Set DialogBox = Application.FileDialog(msoFileDialogFilePicker)

DialogBox.Title = "Select file for " & FileType

DialogBox.Filters.Clear

DialogBox.Show

If DialogBox.SelectedItems.Count = 1 Then

    path = DialogBox.SelectedItems(1)
    ActiveCell.Offset(0, 1).Value = path
    Range("A1").Select

End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,068
Messages
6,122,950
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top