xlDialogImportTextFile txt file name

  • Thread starter Thread starter FallenFigLeaf
  • Start date Start date
F

FallenFigLeaf

I am calling xlDialogImportTextFile, selecting the txt file to import, and
then manipulating the imported data.

How do I capture the name of the txt file I selected to import and still use
xlDialogImportTextFile?
 
Not sure if it's possible. The following is how I do that sort of thing - it
captures the file path which you can then feed into other routines (the If is
there to stop users picking more than one file - you may want to let them!):

Sub ReturnFile()
Dim dlg As FileDialog
Dim strPath As String

OpenAgain:
Set dlg = Application.FileDialog(msoFileDialogFilePicker)
With dlg
If .Show = -1 Then
If .SelectedItems.Count > 1 Then
MsgBox "You must open only one file."
GoTo OpenAgain
End If
strPath = .SelectedItems(1)
Else
Exit Sub
End If
End With
Set dlg = Nothing
MsgBox strPath
End Sub
 
Many thanks,
Unfortunately, this routine does not launch the txt import process, and
since the file of interest is a txt, it does not open as a "workbook" or as
anything. Your routine works great for xl files, by capturing the path, but
not for other types of files. Thanks none the less.
 
Yes, I tried this approach previously to find that even though it limits file
choices to txt, and captures the path, it does not launch the Import
function. Too bad.
 
Back
Top