View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Rech Jim Rech is offline
external usenet poster
 
Posts: 2,718
Default Save as txt-file macro

This isn't a problem related to your macro specifically. It's how Excel
saves tab delimited text files. If you enter this data in a sheet:

aaa aaa aaa
aaa
aaa aaa aaa
aaa aaa aaa

and save it via File, save As in that format you'll get the same number of
tabs on each line in the text file. So for the second line you'd get "aaa"
<tab<tab. That's just how Excel works and you cannot change it, as far as
I know.

When you don't like how Excel creates text files, and people frequently
don't, you have to use a macro to create the file. chip Pearson has an
example of exporting a text file at the bottom of this page. This isn't
exactly what you need but you can modify it to use tabs:

http://www.cpearson.com/excel/imptext.htm

--
Jim
"Beginner81" wrote
in message ...
|
| Hi everyone,
|
| I tried to save my xls-sheets to txt-files with a following macro:
|
| Sub SaveFiles()
| Dim sh As Worksheet
| For Each sh In ActiveWorkbook.Worksheets
| ' copy the sheet to its own workbook
| sh.Copy
| ActiveWorkbook.SaveAs "C:\Temp\" & sh.Name & ".txt", _
| FileFormat:=xlTextWindows
| ActiveWorkbook.Close SaveChanges:=False
| Next
| End Sub
|
| Everything is fine except one thing. There comes some extra tabs to the
| end of some lines in my txt-files. What is the best way to avoid those
| empty spaces?
| Is it possible to make some kind of loop to my macro? Or is there an
| existing "command" (member) in some class?
|
| I really appreciate any of your tips!
|
| -Beginner81-
|
|
| --
| Beginner81
| ------------------------------------------------------------------------
| Beginner81's Profile:
http://www.excelforum.com/member.php...o&userid=25389
| View this thread: http://www.excelforum.com/showthread...hreadid=388629
|