On my form there is a textbook which comments are written. I need it to save the comments every time the file is closed and when opened again the comments should appear. It should also save any editing done.
I assume you mean "TextBox" not "TextBook"
One way is to hold the textbox text in a cell somewhere within the workbook
The code below
- automatically saves the workbook when it is closed
- loads UserForm1 when the file is opened
- when UserForm is loaded latest text is auto-loaded into TextBox1
- automatically writes the text in TextBox1 to cell A1
Amend UserForm1, TextBox1, SheetName, Range("A1") to match the names in your workbook
Code:
[COLOR=#ff0000]I[/COLOR][COLOR=#ff0000]n ThisWorkbook module[/COLOR]
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save
ThisWorkbook.Saved = True
End Sub
Private Sub Workbook_Open()
UserForm1.Show
End Sub
Code:
[COLOR=#ff0000]In userform code window[/COLOR]
Private Sub TextBox1_Change()
Sheets("SheetName").Range("A1").Value = Me.TextBox1.Text
End Sub
Private Sub UserForm_Activate()
Me.TextBox1.Text = Sheets("SheetName").Range("A1").Value
End Sub
Private Sub UserForm_Initialize()
Me.TextBox1.Text = Sheets("SheetName").Range("A1").Value
End Sub
We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel
Which adblocker are you using?
Disable AdBlock
Follow these easy steps to disable AdBlock
1)Click on the icon in the browser’s toolbar. 2)Click on the icon in the browser’s toolbar. 2)Click on the "Pause on this site" option.
Go back
Disable AdBlock Plus
Follow these easy steps to disable AdBlock Plus
1)Click on the icon in the browser’s toolbar. 2)Click on the toggle to disable it for "mrexcel.com".
Go back
Disable uBlock Origin
Follow these easy steps to disable uBlock Origin
1)Click on the icon in the browser’s toolbar. 2)Click on the "Power" button. 3)Click on the "Refresh" button.
Go back
Disable uBlock
Follow these easy steps to disable uBlock
1)Click on the icon in the browser’s toolbar. 2)Click on the "Power" button. 3)Click on the "Refresh" button.