用于向用户表单中的多页添加标签的代码

时间:2014-01-10 20:22:48

标签: vba excel-vba excel

您好我有一个代码可以创建一个用户表单,并且还向该用户表单添加了一个多页面,然后我需要在该用户表单中添加一个Label Inside。以及文本框和按钮。这就是我所拥有的。

Sub CreateUserForm()
Dim myForm As Object
Dim NewFrame As MSForms.Frame
Dim NewButton As MSForms.CommandButton
Dim NewButton1 As MSForms.CommandButton
Dim NewButton2 As MSForms.CommandButton
Dim NewButton3 As MSForms.CommandButton
Dim NewTextBox As MSForms.TextBox
Dim NewMultiPage As MSForms.MultiPage
'Dim NewTextBox As MSForms.TextBox
Dim NewLabel As MSForms.Label
'Dim NewOptionButton As MSForms.OptionButton
'Dim NewCheckBox As MSForms.CheckBox
Dim X As Integer
Dim Line As Integer

'This is to stop screen flashing while creating form
Application.VBE.MainWindow.Visible = False

Set myForm = ThisWorkbook.VBProject.VBComponents.Add(3)

'Create the User Form
With myForm
    .Properties("Caption") = "Job Template"
    .Properties("Width") = 500
    .Properties("Height") = 500
End With

'Create Multipage
Set NewMultiPage = myForm.designer.Controls.Add("Forms.MultiPage.1")
With NewMultiPage
    .name = "lst_1"
    .Top = 10
    .Left = 10
    .Width = 350
    .Height = 450
    .Font.Size = 8
    .Font.name = "Tahoma"
    .Pages.Remove ("Page2")



End With


'This is where i want the code to put stuff inside of the MultiPages.







'Create CommandButton in UserForm
Set NewButton = myForm.designer.Controls.Add("Forms.commandbutton.1")
With NewButton
    .name = "cmd_1"
    .Caption = "Add Rev"
    .Accelerator = "M"
    .Top = 10
    .Left = 410
    .Width = 75
    .Height = 20
    .Font.Size = 8
    .Font.name = "Tahoma"
    .BackStyle = fmBackStyleOpaque
End With
'Create CommandButton in UserForm
Set NewButton1 = myForm.designer.Controls.Add("Forms.commandbutton.1")
With NewButton1
    .name = "cmd_2"
    .Caption = "Remove Rev"
    .Accelerator = "M"
    .Top = 40
    .Left = 410
    .Width = 75
    .Height = 20
    .Font.Size = 8
    .Font.name = "Tahoma"
    .BackStyle = fmBackStyleOpaque
End With
'Create CommandButton in UserForm
Set NewButton2 = myForm.designer.Controls.Add("Forms.commandbutton.1")
With NewButton2
    .name = "cmd_3"
    .Caption = "Enter Information"
    .Accelerator = "M"
    .Top = 70
    .Left = 410
    .Width = 75
    .Height = 20
    .Font.Size = 8
    .Font.name = "Tahoma"
    .BackStyle = fmBackStyleOpaque
End With
'Create CommandButton in UserForm
Set NewButton3 = myForm.designer.Controls.Add("Forms.commandbutton.1")
With NewButton3
    .name = "cmd_4"
    .Caption = "Save"
    .Accelerator = "M"
    .Top = 100
    .Left = 410
    .Width = 75
    .Height = 20
    .Font.Size = 8
    .Font.name = "Tahoma"
    .BackStyle = fmBackStyleOpaque
End With

1 个答案:

答案 0 :(得分:1)

'Create Multipage
Set NewMultiPage = myForm.designer.Controls.Add("Forms.MultiPage.1")
With NewMultiPage
    .Name = "lst_1"
    '...
End With

'put stuff inside of the MultiPages.
Set NewButton = NewMultiPage.Pages(0).Controls.Add("Forms.commandbutton.1")
With NewButton
    .Name = "blah"
    '...
End With
相关问题