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.

link|improve this question
feedback

1 Answer

This will do it:

Sub getafile()
    Dim fStr As String

    With Application.FileDialog(msoFileDialogFilePicker)
        .Show
        If .SelectedItems.Count = 0 Then
            MsgBox "Cancel Selected"
            End
        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
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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