Share via


Enabled、EnterFieldBehavior、SelLength、SelStart、SelText 屬性範例

下列範例會追蹤選取範圍相關的屬性 (SelLengthSelStartSelText) ,這些屬性會在使用者移動插入點時變更,並使用鍵盤擴充選取範圍。

此範例也會使用 EnabledEnterFieldBehavior 屬性。

若要使用本範例,請將此範例程式碼複製到表單的宣告部分中。 請確定該表單包含:

Private Sub TextBox1_KeyUp(ByVal KeyCode As _ 
 MSForms.ReturnInteger, ByVal Shift As Integer) 
 TextBox2.Text = TextBox1.SelStart 
 TextBox3.Text = TextBox1.SelLength 
 TextBox4.Text = TextBox1.SelText 
End Sub
Private Sub UserForm_Initialize() 
 TextBox1.MultiLine = True 
 TextBox1.EnterFieldBehavior = _ 
 fmEnterFieldBehaviorRecallSelection 
 
 TextBox1.Text = "Type your text here. Use " _ 
 & "CTRL+ENTER to start a new line." 
End Sub

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應