Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to get rid of "^M" in the output file

I'm new to Excel vba programming, so I'm not sure if I'm doing the
right thing.

In my macro, if I do:

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''

Dim fileName As String
Dim colIndex As Integer
Dim rwIndex As Integer

fileName = "test.txt"
colIndex = 4

Open fileName For Output As #1

For rwIndex = 2 To 10
Print #1, Cells(rwIndex, colIndex).Value
Next rwIndex

close #1

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''

What I got in the output file were lines that ended with "^M". How can
I remove these characters?

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default how to get rid of "^M" in the output file

Nothing in your code to indicate these "^M" chars were added, so I can only
assume they are in the cell values.
Check the source data.

Also, check the help for "FreeFile".

NickHK

"gordian" wrote in message
ups.com...
I'm new to Excel vba programming, so I'm not sure if I'm doing the
right thing.

In my macro, if I do:

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''

Dim fileName As String
Dim colIndex As Integer
Dim rwIndex As Integer

fileName = "test.txt"
colIndex = 4

Open fileName For Output As #1

For rwIndex = 2 To 10
Print #1, Cells(rwIndex, colIndex).Value
Next rwIndex

close #1

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''

What I got in the output file were lines that ended with "^M". How can
I remove these characters?

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default how to get rid of "^M" in the output file

I bet that Gordian means that ^M is the carriage return character
(vbcr=chr(13)).

It's for end of line (along with vblf=(chr(10)) in DOS files.

But I'm not sure what the OP really wants.

A one line text file?

Print #1, Cells(rwIndex, colIndex).Value;
or
Print #1, Cells(rwIndex, colIndex).Value & " ";

or what???

To the OP:

Maybe it's just your text editor that's giving you the wrong impression. Try
opening the text file in Notepad. Does it look ok?

NickHK wrote:

Nothing in your code to indicate these "^M" chars were added, so I can only
assume they are in the cell values.
Check the source data.

Also, check the help for "FreeFile".

NickHK

"gordian" wrote in message
ups.com...
I'm new to Excel vba programming, so I'm not sure if I'm doing the
right thing.

In my macro, if I do:

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''

Dim fileName As String
Dim colIndex As Integer
Dim rwIndex As Integer

fileName = "test.txt"
colIndex = 4

Open fileName For Output As #1

For rwIndex = 2 To 10
Print #1, Cells(rwIndex, colIndex).Value
Next rwIndex

close #1

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''

What I got in the output file were lines that ended with "^M". How can
I remove these characters?

Thanks


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default how to get rid of "^M" in the output file

Dave,
I see what you mean. If the OP is opening the output file in a different
environment that does not expect the normal end of line combination, then
problems will arise.
As you say, depends what the aim is .

NickHK

"Dave Peterson" wrote in message
...
I bet that Gordian means that ^M is the carriage return character
(vbcr=chr(13)).

It's for end of line (along with vblf=(chr(10)) in DOS files.

But I'm not sure what the OP really wants.

A one line text file?

Print #1, Cells(rwIndex, colIndex).Value;
or
Print #1, Cells(rwIndex, colIndex).Value & " ";

or what???

To the OP:

Maybe it's just your text editor that's giving you the wrong impression.

Try
opening the text file in Notepad. Does it look ok?

NickHK wrote:

Nothing in your code to indicate these "^M" chars were added, so I can

only
assume they are in the cell values.
Check the source data.

Also, check the help for "FreeFile".

NickHK

"gordian" wrote in message
ups.com...
I'm new to Excel vba programming, so I'm not sure if I'm doing the
right thing.

In my macro, if I do:

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''

Dim fileName As String
Dim colIndex As Integer
Dim rwIndex As Integer

fileName = "test.txt"
colIndex = 4

Open fileName For Output As #1

For rwIndex = 2 To 10
Print #1, Cells(rwIndex, colIndex).Value
Next rwIndex

close #1

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''

What I got in the output file were lines that ended with "^M". How can
I remove these characters?

Thanks


--

Dave Peterson



Reply
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
printing i am getting this window "output file name" Derek S Excel Discussion (Misc queries) 1 January 5th 10 01:14 AM
How Might I "Mail Merge" Data For Multiple .txt File Output? [email protected] Excel Discussion (Misc queries) 3 January 8th 07 05:44 AM
How Might I "Mail Merge" Data For Multiple .txt File Output? [email protected] Excel Programming 2 January 8th 07 05:44 AM
Insert "-" in text "1234567890" to have a output like this"123-456-7890" Alwyn Excel Discussion (Misc queries) 3 October 25th 05 11:36 PM
"Unable to Open File" - excel output of Datagrid <-help needed Steve Chatham[_2_] Excel Programming 0 February 25th 04 07:59 PM


All times are GMT +1. The time now is 11:35 PM.

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

About Us

"It's about Microsoft Excel"