VBA Excel Save Copy as txt File

こ雲淡風輕ζ 提交于 2019-12-11 01:49:20

问题


Is it possible to save a copy of a workbook as txt file?

I tried ThisWorkbook.SaveCopyAs("wb.txt"). However this saves the excel with txt without any file conversion. So when I open the text file no data is displayed.


回答1:


Another way

ThisFile = "Filename"
code.....
ActiveWorkbook.SaveAs Filename:="\folderlocation\" & ThisFile & ".txt", FileFormat:=xlText



回答2:


Application.DisplayAlerts = False
Dim s As String
s = ActiveWorkbook.FullName
s = Replace(s, "xlsx", "txt")
ActiveWorkbook.SaveAs Filename:=s, FileFormat:=xlCurrentPlatformText
ActiveWorkbook.Close
Application.DisplayAlerts = True

This will silently save file in txt format and close original file.

Also you can find some info here.



来源:https://stackoverflow.com/questions/36478774/vba-excel-save-copy-as-txt-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!