title: VBA Excel Import .txt with User-Input file name
body: <p>I'm not sure if this is possible, but I would like to have a user enter the file name of a text file (not the entire C:\ thing, but just the name) that is to be imported into an excel spreadsheet. I've already got the code for inputting the text file (space delimited) to the spreadsheet, but I'd really like to not go back and change the code every time I want to import another text file. Is this possible? The file is currently called data.txt, but it will most likely be in the form Data_MM_DD_YY</p>
  
  <p>My current code is as follows: </p>
  
  <pre><code>Option Explicit
  
  
  Public Sub ImportTextFile(FName As String, Sep As String)
  
  Dim RowNdx As Long
  Dim ColNdx As Integer
  Dim TempVal As Variant
  Dim WholeLine As String
  Dim Pos As Integer
  Dim NextPos As Integer
  Dim SaveColNdx As Integer
  
  Application.ScreenUpdating = False
  
  
  SaveColNdx = ActiveCell.Column
  RowNdx = ActiveCell.Row
  
  Open FName For Input Access Read As #1
  
  Name = InputBox("Enter the name of the text file")
  
  
  While Not EOF(1)
      Line Input #1, WholeLine
      If Right(WholeLine, 1) &lt;&gt; Sep Then
          WholeLine = WholeLine &amp; Sep
      End If
      ColNdx = SaveColNdx
      Pos = 1
      NextPos = InStr(Pos, WholeLine, Sep)
      While NextPos &gt;= 1
          TempVal = Mid(WholeLine, Pos, NextPos - Pos)
          Cells(RowNdx, ColNdx).Value = TempVal
          Pos = NextPos + 1
          ColNdx = ColNdx + 1
          NextPos = InStr(Pos, WholeLine, Sep)
      Wend
      RowNdx = RowNdx + 1
  Wend
  
  EndMacro:
  On Error GoTo 0
  Application.ScreenUpdating = True
  Close #1
  End Sub
  
  Sub DoTheImport()
  ImportTextFile FName:="C:\Users\A0K045\Documents\Name).txt", Sep:=" "
  End Sub
  </code></pre>
  
  <p>Any help would be greatly appreciated! And if it's not possible, is there anything similar to this that is possible? </p>