0

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.

1 Answer 1

2

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

You must log in to answer this question.

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