Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.