共用方式為


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

以下範例追蹤 SelLengthSelStartSelText) (選取相關的屬性,這些屬性會隨著使用者移動插入點並使用鍵盤延伸選取範圍而改變。

此範例同樣使用 EnabledEnterFieldBehavior 屬性。

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

  • 一個大型 文字框 ,名為 TextBox1。
  • 三個 TextBox 控制項集中在名為 TextBox2 到 TextBox4 的欄位中。
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 支援與意見反應