title: VBA Excel: Specify Path To Import Text File Via Text Box on Userform
body: <p>Okay I know this is a really stupid way to do this, but I have a userform that allows user input for 3 things: the path in which a text file is located, the name of the text file, and the location in which to import the data from the text file. What I want to do is to follow the path that the user inputs, get the text file via the name the user inputs, and place whatever the text file contains into the range that the user inputs.</p>
  
  <p>I know it can be easily be simplified using Application.GetOpenFilename, but you gotta do what you gotta do. What I need to do is to be able to specify the path, specify the text file, and the location in which to load all of the text from a text file into a range with comma delimiters. Currently the program either breaks on the line ".Refresh BackgroundQuery:=False" or doesn't do anything at all, and I don't know how to move forward. My code is as follows- apologies for the messiness. Please let me know if you can help!</p>
  
  <pre><code>Private Sub OKButton_Click()
  
  Dim filePath As String, destin As String, fileName As Variant
  
  destin = DestinationTextBox.Value
  fileName = TextFileNameTextBox.Value
  
  filePath = Dir(FileLocationTextBox.Value)
  
  'filePath = Application.GetOpenFilename("Text Files (*.txt), *.txt")
  'oh, if only
  
      With ActiveSheet.QueryTables.Add(Connection:="TEXT;" &amp; _
      filePath, Destination:=Range(destin))
          .Name = fileName &amp; ".txt"
          .FieldNames = True
          .RowNumbers = False
          .FillAdjacentFormulas = False
          .PreserveFormatting = True
          .RefreshOnFileOpen = False
          .RefreshStyle = xlInsertDeleteCells
          .SavePassword = False
          .SaveData = True
          .AdjustColumnWidth = True
          .RefreshPeriod = 0
          .TextFilePromptOnRefresh = False
          .TextFilePlatform = 437
          .TextFileStartRow = 1
          .TextFileParseType = xlDelimited
          .TextFileTextQualifier = xlTextQualifierNone
          .TextFileConsecutiveDelimiter = True
          .TextFileTabDelimiter = False
          .TextFileSemicolonDelimiter = False
          .TextFileCommaDelimiter = True
          .TextFileSpaceDelimiter = False
          .TextFileOtherDelimiter = "" &amp; Chr(10) &amp; ""
          .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, _
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
          .TextFileTrailingMinusNumbers = True
          .Refresh BackgroundQuery:=False
  End With
  End Sub
  </code></pre>