File picker to store file name as cell or variable

bmpreston

Board Regular
Joined
Jun 18, 2016
Messages
113
Good afternoon,

I have a sharepoint site that several users store the same template file on. Each in a different folder, sub folder, file name; however each with the same structure.

Is there a way to allow a user to select the file in a file picker, and save that as a variable or in cell that I could then reference in further code?

I would like each user to be able to select ‘their file’ then I use a basic formula to show the contents of that cell, (cell A205) on this sheet.

Making individual files all day for each separate user is intensive specially if the remote file changes once a year etc.


Thabks
 

Some videos you may like

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

severynm

Board Regular
Joined
Jan 8, 2021
Messages
51
Office Version
  1. 365
Platform
  1. Windows
The following function opens the file picker (for Windows) and returns the full path of the file selected (including path, filename, and extension).

All you need to do is customize this for your own use, and write to a cell with SheetName.Range("A205").Value = OpenFile()
VBA Code:
''==========================================================================================================================
'' Name:      OpenFile()
'' Desc:      Opens file dialog and prompts user to select a file
'' Called by: cmd_ImportData_Click()
'' Args:      N/A
'' Comments:  (1) Default path is E:\! Sewing (usb)
''            (2) Limits selection to one file at a time
''            (3) Code from https://www.chicagocomputerclasses.com/excel-vba-display-a-file-open-dialog-and-open-the-file-excel-functions/
''==========================================================================================================================
Private Function OpenFile() As String
    Dim fullpath As String
    
    On Error Resume Next
    With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = False 'user can only select one file not multiple
        .InitialFileName = "E:\..." 'initial location to open the dialog to
        .Show
        
        fullpath = .SelectedItems.Item(1)
    End With
    
    'Quit the procedure if the user didn't select the type of file we need.
    If InStr(fullpath, "Sew3") = 0 Then
        MsgBox ("Incorrect file type selected.")
        Exit Function
    End If
    On Error GoTo 0

    OpenFile = fullpath
End Function
 

Watch MrExcel Video

Forum statistics

Threads
1,126,965
Messages
5,621,871
Members
415,862
Latest member
nascaline

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
Top