Controlar o comportamento da caixa de texto ao clicar em Inserir

O exemplo a seguir usa a propriedade EnterKeyBehavior para controlar o efeito enter em uma Caixa de Texto. Neste exemplo, o usuário pode especificar uma TextBox de linha única ou com várias linhas.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • A TextBox named TextBox1.

  • Dois controles ToggleButton chamados ToggleButton1 e ToggleButton2.

Dim TextBox1 
Dim ToggleButton1 
Dim ToggleButton2 
 
Sub Item_Open() 
 set TextBox1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("TextBox1") 
 set ToggleButton1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("ToggleButton1") 
 set ToggleButton2 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("ToggleButton2") 
 TextBox1.EnterKeyBehavior = True 
 ToggleButton1.Caption = "EnterKeyBehavior is True" 
 ToggleButton1.Width = 70 
 ToggleButton1.Value = True 
 
 TextBox1.MultiLine = True 
 ToggleButton2.Caption = "MultiLine is True" 
 ToggleButton2.Width = 70 
 ToggleButton2.Value = True 
 
 TextBox1.Height = 100 
 TextBox1.WordWrap = True 
 TextBox1.Text = "Type your text here. If EnterKeyBehavior is True,"& _ 
 " press Enter to start a new line. Otherwise, press SHIFT+ENTER." 
End Sub 
 
Sub ToggleButton1_Click() 
 If ToggleButton1.Value = True Then 
 TextBox1.EnterKeyBehavior = True 
 ToggleButton1.Caption = "EnterKeyBehavior is True" 
 Else 
 TextBox1.EnterKeyBehavior = False 
 ToggleButton1.Caption = "EnterKeyBehavior is False" 
 End If 
End Sub 
 
Sub ToggleButton2_Click() 
 If ToggleButton2.Value = True Then 
 TextBox1.MultiLine = True 
 ToggleButton2.Caption = "MultiLine TextBox" 
 Else 
 TextBox1.MultiLine = False 
 ToggleButton2.Caption = "Single-line TextBox" 
 End If 
End Sub

Suporte e comentários

Tem dúvidas ou quer enviar comentários sobre o VBA para Office ou sobre esta documentação? Confira Suporte e comentários sobre o VBA para Office a fim de obter orientação sobre as maneiras pelas quais você pode receber suporte e fornecer comentários.