-
I'm having trouble saving data to a textfile. I can save the filename but cannot write the data to that file. Can someone help??
Heres an example of the code I have so far:
On Error Resume Next
CommonDialog1.Filter = "All Text Files (*.txt)|*.txt"
CommonDialog1.ShowSave
strOpenFile = CommonDialog1.Filename
Set ts = fso.CreateTextFile(strOpenFile, True)
strData = Text1
ts.Write (strData)
ts.Close
-
Rich text boxs have their own built in save feature
Code:
rtb1.savefile "C:\Myfile.txt" , rtfRTF 'to save
rtb1.loadfile "C:\Myfile.txt" , rtfRTF 'to open
-
RichTextBoxes use up a lot more resources too. Next example will save data from Text1 into a file called MyFile.
Code:
Open "MyFile.txt" For Output As #1
Print #1, Text1.Text
Close #1
-
Sub SavetxtFile()
'Assign constants forwriting numeric value
Const ForWriting = 2
'Set fso as object for writing to output file
Set fso = CreateObject("Scripting.FileSystemObject")
'Set SavetxtOutFile = file path
Set SavetxtOutFile = fso.OpenTextFile _
("c:\windows\desktop\savedtxtfile.txt", ForWriting,True)
'Write txt here
SavetxtOutFile.write "Here is the text I have saved."
'Close txt file
Set SavetxtOutFile = Nothing
End Sub