Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Writing Localized Strings In Cells Using Automation | Excel Discussion (Misc queries) | |||
Writing to a text file some data | Excel Programming | |||
WRITING TO A TEXT FILE WITH SPECIFIC FORMAT | Excel Programming | |||
import text-file - strings contain cr-lf | Excel Programming | |||
Writing multilines to a text file without closing | Excel Programming |