简体   繁体   中英

Export excel worksheet to a text file

I would like to know the simplest way to create a text file and then write ALL the data from a worksheet into that file (tab-delimited). I don't only want to write particular cells into the sheet (I want everything on the worksheet) but also don't want to have to have to write every cell. I know the command for writing cells is like this:

open "c:|OUTPUT.txt" for output as #1 print #1, cells(1,2) & cells(2,2) & cells(3,2) ... close

but is there a way to just write all the data from the sheet into a txt file? I want to run this on a loop for many worksheets.

Use the VBA SaveAs method to save it as a .txt by passing xlTextWindows as the FileFormat.

See this page for details on the SaveAs method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM