title: How to select the contents of a textbox once it is activated?
body: <p>I have this simple Userform, where I only have <code>TextBox1</code> and <code>TextBox2</code>. I enter some text in both of them. Assume the focus is on (the cursor is in) the <code>TextBox2</code>. When I click on <code>TextBox1</code>, I want the whole text in this control to be highlighted (selected). Thus I use this code:</p>
  
  <pre><code>Private Sub TextBox1_Enter()
      With TextBox1
          .SetFocus
          .SelStart = 0
          .SelLength = Len(.Text)
      End With
      MsgBox "enter event was fired"
  End Sub
  </code></pre>
  
  <p>There is a <code>MsgBox</code> at the end which is loaded, that means the event works. However, the text is not highlighted. How to fix this?</p>
  
  <p>I use the <code>Enter</code> event and don't want to use the <code>MouseDown</code> event, because I need the code to also work when the <code>TextBox1</code> is activated programatically, so I feel the <code>Enter</code> event to be the best choice, as it's fired in both cases! Another drawback of the <code>MouseDown</code> event is: when I click for the second time on the <code>TextBox1</code>, I would not expect the whole text to be highlighted anymore, because the focus was set on the first click and it was not changed after I clicked on the same control for the second time; so in this case I would like the cursor to act normally (not to keep the text marked).</p>
  
  <p><strong>Update</strong>
  <br>
  When I click once on the <code>TextBox1</code>, I expect to have this result:
  <img src="https://i.stack.imgur.com/DiWuu.jpg" alt="enter image description here">
  <br>If clicked again, the highlight would be removed and the cursor would be placed in the place where it was clicked.</p>