Hi All, is there a way to save the value of the textbox to a notepad when I click the "Save" button?Textbox.PNG
Hi All, is there a way to save the value of the textbox to a notepad when I click the "Save" button?Textbox.PNG
textbox1 being your textbox![]()
Private Sub CommandButton1_Click() Dim filepath As String Dim FN As Object Dim fs As Object Set fs = CreateObject("Scripting.FileSystemObject") Set FN = fs.CreateTextFile("G:\zztest.txt", True) FN.writeline TextBox1.Text FN.Close End Sub
replace File location and file name with where you want it and what you want it called
If you are satisfied with the solution(s) provided, please mark your thread as Solved.
Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.
Hi Sir/Maam it works but i need to save it daily. For example all data i save on the textbox1 will be saved to the notepad as "July 9.txt", tomorrow it will be save as "July 10.txt", and so on or simply it will be saved as what date is the file created... Appreciate your assistance
Last edited by nathan0519; 07-09-2014 at 04:01 AM.
you need to define what your asking better than
you only asked for saving textbox into text
have another variable string and use that to set your filename
Something like this Sir/Ma'am,
Directory = "D:\File\"
Date = Now
Filename = "D:\File\July 10.txt"
---so when I use it here, the "Filename" will hold a value of "D:\File\July 10.txt"
Set FN = fs.CreateTextFile(Filename, True)
this code will use todays date in MMM-YY format![]()
Private Sub CommandButton1_Click() Dim FN As Object Dim fs As Object Dim savename As String savename = "G:\" & (Format(Date, "DD-MMM-YY")) & ".txt" Set fs = CreateObject("Scripting.FileSystemObject") Set FN = fs.CreateTextFile(savename, True) FN.writeline TextBox1.Text FN.Close End Sub
ps this code will overwrite previous files so if you run it twice it will take the latest version
change drive to your needs, i used G because for my testing
Last edited by humdingaling; 07-09-2014 at 08:21 PM.
this code takes value from A1![]()
Private Sub CommandButton1_Click() Dim FN As Object Dim fs As Object Dim savename As String savename = "G:\" & Range("A1") & ".txt" Set fs = CreateObject("Scripting.FileSystemObject") Set FN = fs.CreateTextFile(savename, True) FN.writeline TextBox1.Text FN.Close End Sub
remember that naming conventions apply
characters \ / : * ? " < > | cannot be used
Thank you very much humdingaling. It's ok now
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks