title: VBA - Export excel sheet to a .txt file
body: <p>I am trying to export a particular column from a excel sheet into .txt file format. I would like to allow the user to provide name and location of the file to be saved. </p>
  
  <p>I was able to save it in .xlsx format. Anyone know how to export it into .dat format ?</p>
  
  <p>This is my code for .xlsx export,</p>
  
  <pre><code>Workbooks.Add
  ActiveSheet.Paste
  Cells.Select
  Selection.Columns.AutoFit
  Application.CutCopyMode = False
  
  sFileSaveName = Application.GetSaveAsFilename(InitialFileName:=InitialName, fileFilter:="Excel Files (*.xlsx), *.xls")
  
          If sFileSaveName &lt;&gt; False Then
          ActiveWorkbook.SaveCopyAs sFileSaveName
          MsgBox "File Successfully Saved!"
          ActiveWorkbook.Close
          End if
  </code></pre>
  
  <p>I have tried something like this,</p>
  
  <pre><code>myFile = Application.GetSaveAsFilename(filefilter:="Text Files (*.txt),*txt")
  </code></pre>
  
  <p>But my output got messed up completely and looks like this - <a href="https://i.stack.imgur.com/Mrytf.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mrytf.jpg" alt="Text output"></a></p>
  
  <p>Thanks.</p>