LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Save as txt-file macro

Rather than modify Chip's macro here is one I did:

''Outputs the selection if more than one cell is selected, else entire sheet
Sub OutputActiveSheetAsTabDelim()
Dim SrcRg As Range
Dim CurrRow As Range
Dim CurrCell As Range
Dim CurrTextStr As String
Dim ListSep As String
Dim FName As Variant
Dim ColCount As Integer
Dim CurrCol As Integer
FName = Application.GetSaveAsFilename("", "Tab Delimited File (*.txt),
*.txt")
If FName < False Then
ListSep = vbTab ''Chg to comma, etc for a different separator
If Selection.Cells.Count 1 Then
Set SrcRg = Selection
Else
Set SrcRg = ActiveSheet.UsedRange
End If
ColCount = SrcRg.Columns.Count
Open FName For Output As #1
For Each CurrRow In SrcRg.Rows
CurrCol = 0
CurrTextStr = ""
For Each CurrCell In CurrRow.Cells
CurrCol = CurrCol + 1
CurrTextStr = CurrTextStr & CurrCell.Value & ListSep
Next
While Right(CurrTextStr, 1) = ListSep
CurrTextStr = Left(CurrTextStr, Len(CurrTextStr) - 1)
Wend
Print #1, CurrTextStr
Next
Close #1
End If
End Sub


--
Jim
"Beginner81" wrote
in message ...
|
| Thanks Jim,
|
| it seems to be quite difficult to modify the existing macro (at least
| for me).
|
| Is it possible to get any further tips? If I have (.xls)
|
| aaa aaa aaa
| aaa
| aaa aaa
| aaa aaa aaa aaa
| (and so on)
|
| How should I modify the macro that you mentioned or my own macro to get
| txt file like:
|
| aaa aaa aaa (<-no tab)
| aaa (<-no tabs)
| aaa aaa (<-no tabs)
| aaa aaa aaa aaa
|
| Thanks a lot in advance!
|
|
| --
| Beginner81
| ------------------------------------------------------------------------
| Beginner81's Profile:
http://www.excelforum.com/member.php...o&userid=25389
| View this thread: http://www.excelforum.com/showthread...hreadid=388629
|


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
2007 Macro to Open File, Delete Contents, Save New File Flintstone[_2_] Excel Discussion (Misc queries) 2 February 1st 10 11:25 PM
Macro Save File (Unique file name) SJC Excel Worksheet Functions 5 October 27th 05 10:09 PM
ASP: Open Excel File with Macro, Allow Macro to run, and then save delgados129 Excel Programming 0 March 10th 05 09:35 PM
Macro to insert values from a file and save another sheet as a .txt file Frank[_16_] Excel Programming 2 August 28th 03 01:07 AM
Automate open file, update links, run macro, close and save file Geoff[_7_] Excel Programming 2 August 26th 03 10:13 PM


All times are GMT +1. The time now is 07:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"