Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to have an Excel Macro stop and prompt for the location of file to be imported?

I've created several macros for importing text files but the imported file must always exist in the same location and same filename.

share|improve this question

This will do it:

Sub getafile()
    Dim fStr As String

    With Application.FileDialog(msoFileDialogFilePicker)
        If .SelectedItems.Count = 0 Then
            MsgBox "Cancel Selected"
        End If
        'fStr is the file path and name of the file you selected.
        fStr = .SelectedItems(1)
    End With
    'Replace with your code.
    MsgBox fStr
End Sub
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .