Read Name of Selected File

seekeagle

New Member
Joined
Mar 5, 2009
Messages
23
The code below navigates to a specified location, opens the folder and allows the user to select an Excel file, which will be opened and the file name stored in the variable "File_nam".

Code:
'
******  Get Data from Checked out Laptop
    data_path = "d:\data\CAM_Tool"   
    
 ''''''**** commented out to use access
    If Application.Dialogs(xlDialogOpen).Show(data_path) Then
         ' continue running subroutine
    Else
        Exit Sub
    End If
    File_nam = ActiveWorkbook.Name       ' File Name with Raw Data

I am trying to do something similar but need help getting it working. I would like to give the user the opportunity to navigate to a location of his choice, and select an Access file. I do not want to open the file, but I need to record the name, which will subsequently be used in reading data from the file using ActiveX Data Objects without opening the file.

I know there is an commend called "GetSelectedFile", but cannot get it to work. How do I get the name of a selected file without opening it? Your help will be greatly appreciated.

Thanks,
George,
Fort Worth
 

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.
The property "FileDialog" should do the job; the help on line list this example:
Code:
Sub UseFileDialogOpen()

    Dim lngCount As Long

    ' Open the file dialog
    With Application.FileDialog(msoFileDialogOpen)
        .AllowMultiSelect = True
        .Show

        ' Display paths of each file selected
        For lngCount = 1 To .SelectedItems.Count
            MsgBox .SelectedItems(lngCount)
        Next lngCount

    End With

End Sub
Il will open the file select dialogue box, allow the user to select any number of files, then the mesgbox shows each of the selected file names.

Bye.
 
Upvote 0
George

What is this command 'GetSelectedFile'?
 
Upvote 0
Upvote 0
This should do that:
Code:
Sub test()
    Dim uiFileNames As Variant
    
    uiFileNames = Application.GetOpenFilename(MultiSelect:=True)
    
    If TypeName(uiFileNames) = "Boolean" Then
        MsgBox "nothing selected"
    Else
        With Range("A1")
            .Resize(UBound(uiFileNames), 1) = Application.Transpose(uiFileNames)
        End With
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,258
Members
449,149
Latest member
mwdbActuary

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