在 MultiPage 控制項的表單或頁面上顯示每個控制項的名稱
下列範例會使用Item方法來存取 Microsoft Forms 2.0 Controls集合和Pages集合的個別成員。 使用者選擇 Controls 集合 或 MultiPage的選項按鈕,然後按一下 CommandButton。 適當的控制項名稱會在 標籤中傳回。
若要使用本範例,請將此範例程式碼複製到表單的指令碼編輯器中。 若要執行該程式碼,您需要開啟該表單以啟動 Open 事件。 請確定表單包含:
一個名為 CommandButton1 的 CommandButton 。
一個名為 Label1 的 Label 。
兩個分別名為 OptionButton1 和 OptionButton2 的 OptionButton 控制項。
一個名為 MultiPage1 的 MultiPage 。
Dim ControlsIndex
Sub CommandButton1_Click()
Set Controls = Item.GetInspector.ModifiedFormPages("P.2").Controls
Set OptionButton1 = Controls("OptionButton1")
Set OptionButton2 = Controls("OptionButton2")
Set Label1 = Controls("Label1")
Set MultiPage1 = Controls("MultiPage1")
If OptionButton1.Value = True Then
'Process Controls collection for UserForm
Set MyControl = Controls.Item(ControlsIndex)
Label1.Caption = MyControl.Name
'Prepare index for next control on Userform
ControlsIndex = ControlsIndex + 1
If ControlsIndex >= Controls.Count Then
ControlsIndex = 0
End If
ElseIf OptionButton2.Value = True Then
'Process Current Page of Pages collection
Set MyControl = MultiPage1.Pages.Item(MultiPage1.Value)
Label1.Caption = MyControl.Name
End If
End Sub
Sub Item_Open()
ControlsIndex = 0
Set OptionButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton1")
Set OptionButton2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton2")
Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CommandButton1")
OptionButton1.Caption = "Controls Collection"
OptionButton2.Caption = "Pages Collection"
OptionButton1.Value = True
CommandButton1.Caption = "Get Member Name"
End Sub
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應