ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Writing strings to a text file ? (https://www.excelbanter.com/excel-programming/310963-writing-strings-text-file.html)

Dan Thompson

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

Bob Kilmer

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




Trevor Shuttleworth

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




Dan Thompson

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






All times are GMT +1. The time now is 08:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com