2017-10-16 135 views
0

我想從Excel表導出一個特定列爲.txt文件格式。我想讓用戶提供要保存的文件的名稱和位置。VBA - 將excel表導出爲一個.txt文件

我能夠以.xlsx格式保存它。任何人都知道如何將其導出爲.dat格式?

這是我的.xlsx出口代號,

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 

我已經試過這樣的事情,

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

但我的輸出得到了完全搞砸了,看起來像這樣 - Text output

謝謝。

+2

這可能有助於https://www.mrexcel.com/forum/excel-questions/419731-convert-xls-file-dat-file.html – QHarr

+0

我想這一點,但它失敗 - 只是試圖將一個excel文件保存爲.txt文件 - sFileSaveName = Application.GetSaveAsFilename(InitialFileName:= InitialName,FileFilter:=「(* .txt)」) – Sid29

+0

鏈接是否顯示如何寫出範圍?它是你想要寫入文件的列。 – QHarr

回答

0

您必須包含文件格式以保存爲文本文件:FileFormat:=xlText

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

相關問題