Share via


Page 物件、MultiPage 控制項、Add、Clear、Remove 方法範例

下列範例會使用AddClearRemove方法,在執行時間將控制項加入和移除至 MultiPagePage

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

  • 一個名為 MultiPage1 的 MultiPage
  • 三個名稱分別為 CommandButton1 到 CommandButton3 的 CommandButton 控制項。
Dim MyTextBox As Control 
 
Private Sub CommandButton1_Click() 
Set MyTextBox = MultiPage1.Pages(0).Controls.Add("MSForms" _ 
 & ".TextBox.1", "MyTextBox", Visible) 
End Sub 
 
Private Sub CommandButton2_Click() 
 MultiPage1.Pages(0).Controls.Clear 
End Sub 
 
Private Sub CommandButton3_Click() 
 If MultiPage1.Pages(0).Controls.Count > 0 Then 
 MultiPage1.Pages(0).Controls.Remove "MyTextBox" 
 End If 
End Sub 
 
Private Sub UserForm_Initialize() 
 CommandButton1.Caption = "Add control" 
 CommandButton2.Caption = "Clear controls" 
 CommandButton3.Caption = "Remove control" 
End Sub

支援和意見反應

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