Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 125
Default Writing strings to a text file ?

This is the code I am using to write strings to a .txt file

Function WriteLineNums()
Dim X as Integer
Dim S As String
S = "Line #"
Open "C:\MyTextFile.txt" For Output As #1
For X = 1 To 3
Write #1, S & X
Next X
Close #1
End Function

The problem is I don't want the function to write the Double quotes to the
file.
anyhow this is what the function writes to MyTextFile.txt
"Line #1"
"Line #2"
"Line #3"

And This is what I want it to write
Line #1
Line #2
Line #3

What am I doing wrong ?
Any thoughts would be appreciated.

Thanks
Dan Thompson
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default Writing strings to a text file ?

Use Print #

"Dan Thompson" wrote in message
...
This is the code I am using to write strings to a .txt file

Function WriteLineNums()
Dim X as Integer
Dim S As String
S = "Line #"
Open "C:\MyTextFile.txt" For Output As #1
For X = 1 To 3
Write #1, S & X
Next X
Close #1
End Function

The problem is I don't want the function to write the Double quotes to

the
file.
anyhow this is what the function writes to MyTextFile.txt
"Line #1"
"Line #2"
"Line #3"

And This is what I want it to write
Line #1
Line #2
Line #3

What am I doing wrong ?
Any thoughts would be appreciated.

Thanks
Dan Thompson



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Writing strings to a text file ?

Try using Print instead of write

An example from the VBA Help:

Sub test2()
Open "TESTFILE.TXT" For Output As #1 ' Open file for output.
Print #1, "This is a test" ' Print text to file.
Print #1, ' Print blank line to file.
Print #1, "Zone 1"; Tab; "Zone 2" ' Print in two print zones.
Print #1, "Hello"; " "; "World" ' Separate strings with space.
Print #1, Spc(5); "5 leading spaces " ' Print five leading spaces.
Print #1, Tab(10); "Hello" ' Print word at column 10.
Close #1
End Sub

Regards

Trevor


"Dan Thompson" wrote in message
...
This is the code I am using to write strings to a .txt file

Function WriteLineNums()
Dim X as Integer
Dim S As String
S = "Line #"
Open "C:\MyTextFile.txt" For Output As #1
For X = 1 To 3
Write #1, S & X
Next X
Close #1
End Function

The problem is I don't want the function to write the Double quotes to

the
file.
anyhow this is what the function writes to MyTextFile.txt
"Line #1"
"Line #2"
"Line #3"

And This is what I want it to write
Line #1
Line #2
Line #3

What am I doing wrong ?
Any thoughts would be appreciated.

Thanks
Dan Thompson



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 125
Default Writing strings to a text file ?

Print # works great!
Thanks Bob
Cheers


"Bob Kilmer" wrote:

Use Print #

"Dan Thompson" wrote in message
...
This is the code I am using to write strings to a .txt file

Function WriteLineNums()
Dim X as Integer
Dim S As String
S = "Line #"
Open "C:\MyTextFile.txt" For Output As #1
For X = 1 To 3
Write #1, S & X
Next X
Close #1
End Function

The problem is I don't want the function to write the Double quotes to

the
file.
anyhow this is what the function writes to MyTextFile.txt
"Line #1"
"Line #2"
"Line #3"

And This is what I want it to write
Line #1
Line #2
Line #3

What am I doing wrong ?
Any thoughts would be appreciated.

Thanks
Dan Thompson




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
Writing Localized Strings In Cells Using Automation VirGin Excel Discussion (Misc queries) 0 March 7th 05 01:04 PM
Writing to a text file some data Tom Ogilvy Excel Programming 0 September 9th 04 04:25 PM
WRITING TO A TEXT FILE WITH SPECIFIC FORMAT [email protected] Excel Programming 2 December 27th 03 05:04 AM
import text-file - strings contain cr-lf John A Grandy Excel Programming 2 August 25th 03 06:38 PM
Writing multilines to a text file without closing ccdubs Excel Programming 1 July 10th 03 07:43 AM


All times are GMT +1. The time now is 06:04 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"