Unprotecting a sheet once a text box is selected

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Can you unprotect a sheet once a text box is selected and then reprotect it again when it is unselected?

I do not want to use active x text boxes, just normal text boxes.
 
Disregard the FORM stuff.

On Sheet, use the Sheet Module :

VBA Code:
Option Explicit

Private Sub TextBox1_GotFocus()
MsgBox "Hi"
End Sub

'Replace MsgBox with your macro or a call to a macro

Private Sub TextBox1_LostFocus()
MsgBox "Bye"
End Sub

Easiest way to get to the Sheet Code Module is to right click on the sheet tab and select VIEW CODE.
The code window is the large white pane on the right.
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
But I want to lock the spreadsheet. Can you lock the spreadsheet and still be able to press enter for additional text in the text box?
 
Upvote 0
I added this code to my sheet.

VBA Code:
Private Sub TextBox4_GotFocus()
    ActiveSheet.Unprotect
End Sub

'Replace MsgBox with your macro or a call to a macro

Private Sub TextBox4_LostFocus()
    ActiveSheet.Protect
End Sub

Whenever the worksheet is unprotected, I am able to go to new lines fine but with the above code and the workbook protected, it seems to jump to a random unlocked cell whenever I press enter.
 
Upvote 0
If I don't have anything selected, cell A11911 is selected. If I have a cell within the unlocked cells selected and then type in the box and press enter, the cell below the cell I had selected before I hit enter gets selected
 
Upvote 0
I want to be able to go to a new line within the text box. Depending on how much information is needed above it, the box could be anywhere on the sheet as it moves with the data. I enter a table row and that pushes it down.
 
Upvote 0
My apologies ... someone else will need to step in and assist.

Anyone ??
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,540
Members
449,038
Latest member
Guest1337

We've detected that you are using an adblocker.

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.
Go back
Back
Top