我有一个多页,我成功地将作为我的引用页面的第一页的元素复制到动态创建的新页面。
我的问题是,如何在多页面控件的页面内设置命令按钮的操作? 我的目标是单击任何页面上的按钮,然后弹出另一个表单。
我该怎么做? 从Android 到VB 的调整是相当困难的。我真的很感谢你们的帮助。
这是我在克隆页面中的代码。
i = 0
MultiPage1.Pages.Add
MultiPage1.Pages(i).Controls.Copy
i = i + 1
MultiPage1.Pages(i).Paste
For Each ctl In Me.MultiPage1.Pages(i).Controls
If TypeOf ctl Is MSForms.Label Then
'~~~ code omitted
Select Case ctl.Tag
Case "startTime"
ctl.Caption = "4:00pm"
End Select
End If
Next
这就是它的样子。
该按钮将连接页面内的所有字符串。连接的字符串将显示在另一个用户表单上。
最佳答案
您可能最好在功能区中创建一个按钮,以便它在所有页面上都可用:
http://chandoo.org/wp/2012/02/27/how-to-add-your-own-macros-to-excel-ribbon/
编辑:
我的错,我以为您指的是工作表而不是用户窗体中的 VBA MultiPage。
看看这个。我能够让这项工作为我工作:
Assign code to a button created dynamically
第一类:
Option Explicit
Public WithEvents CmdEvents As MSForms.CommandButton
Private Sub CmdEvents_Click()
MsgBox "yo"
End Sub
带有 MultiPage 对象的用户表单:
Option Explicit
Dim cmdArray() As New Class1
Private Sub CommandButton1_Click()
Dim newControl As Control
Set newControl = Me.MultiPage1.Pages(0).Controls.Add("Forms.CommandButton.1", "NewCommand", True)
newControl.Object.Caption = "hello"
newControl.Left = 50
newControl.Top = 50
ReDim Preserve cmdArray(1 To 1)
Set cmdArray(1).CmdEvents = newControl
Set newControl = Nothing
End Sub
关于excel - 如何在Excel VBA中控制多页内的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15192801/