添加、剪切、粘贴方法、Page 对象、多页控件示例Add, Cut, Paste methods, Page object, MultiPage control example

以下示例使用**AddCutPaste** 方法从**** 页**页面的页面** 中剪切和粘贴控件。The following example uses the Add, Cut, and Paste methods to cut and paste a control from a Page of a MultiPage. 剪切和粘贴操作中涉及的控件将动态添加到窗体中。The control involved in the cut and paste operations is dynamically added to the form.

本示例假定用户将添加、剪切和粘贴新控件。This example assumes that the user will add, cut, and then paste the new control.

若要使用此示例,请将此示例代码复制到窗体的 Declarations 部分。To use this example, copy this sample code to the Declarations portion of a form. 确保该窗体包含:Make sure that the form contains:

  • 三个名称分别为"CommandButton1"到"CommandButton3"的 CommandButton 控件。Three CommandButton controls named CommandButton1 through CommandButton3.
  • 一个名为"MultiPage1"的 MultiPageA MultiPage named MultiPage1.
Dim MyTextBox As Control 
 
Private Sub CommandButton1_Click() 
 Set MyTextBox = MultiPage1.Pages(MultiPage1.Value).Controls_ 
 .Add("MSForms.TextBox.1", "MyTextBox", Visible) 
 CommandButton2.Enabled = True 
 CommandButton1.Enabled = False 
End Sub 
 
Private Sub CommandButton2_Click() 
 MultiPage1.Pages(MultiPage1.Value).Controls.Cut 
 CommandButton3.Enabled = True 
 CommandButton2.Enabled = False 
End Sub 
 
Private Sub CommandButton3_Click() 
 Dim MyPage As Object 
 Set MyPage = _ 
 MultiPage1.Pages.Item(MultiPage1.Value) 
 
 MyPage.Paste 
 CommandButton3.Enabled = False 
End Sub 
 
Private Sub UserForm_Initialize() 
 CommandButton1.Caption = "Add" 
 CommandButton2.Caption = "Cut" 
 CommandButton3.Caption = "Paste" 
 
 CommandButton1.Enabled = True 
 CommandButton2.Enabled = False 
 CommandButton3.Enabled = False 
End Sub

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.