0

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.

I was able to save it in .xlsx format. Anyone know how to export it into .dat format ?

This is my code for .xlsx export,

Workbooks.Add
ActiveSheet.Paste
Cells.Select
Selection.Columns.AutoFit
Application.CutCopyMode = False

sFileSaveName = Application.GetSaveAsFilename(InitialFileName:=InitialName, fileFilter:="Excel Files (*.xlsx), *.xls")

        If sFileSaveName <> False Then
        ActiveWorkbook.SaveCopyAs sFileSaveName
        MsgBox "File Successfully Saved!"
        ActiveWorkbook.Close
        End if

I have tried something like this,

myFile = Application.GetSaveAsFilename(filefilter:="Text Files (*.txt),*txt")

But my output got messed up completely and looks like this - Text output

Thanks.

  • 2
    This might help https://www.mrexcel.com/forum/excel-questions/419731-convert-xls-file-dat-file.html – QHarr Oct 16 '17 at 10:48
  • I am trying that, but it fails - Just trying to save an excel file as .txt file - sFileSaveName = Application.GetSaveAsFilename(InitialFileName:=InitialName, FileFilter:="(*.txt)") – Student of the Digital World Oct 16 '17 at 11:15
  • Doesn't the link show how to write a range out? It is the column you want to write out to a file. – QHarr Oct 16 '17 at 11:17
  • Selecting the range or a column is not a problem. The problem lies on exporting the data into .txt format - A notepad file. I am not able to open the dialog box. I would like to save the excel file straight away as .txt file – Student of the Digital World Oct 16 '17 at 11:18
  • Please try `ActiveWorkbook.SaveAs Filename:=YourTextFile.txt, FileFormat:=xlText` –  Oct 16 '17 at 12:31

1 Answers1

0

You must include a file format to save as text file: FileFormat:=xlText.

ActiveWorkbook.SaveAs Filename:=YourTextFile.txt, FileFormat:=xlText