VBA - 以编程方式在设计模式下而不是在运行时向用户窗体添加帧



我需要编辑我现有的表单(testFORM)...添加 80 张图片。

我不想在运行时制作它,而是永久更改我的表单。

下面是模块 1 中的代码:

Sub addImage()
Dim imgNew As Object
Dim imgNewCounter As Integer
For imgNewCounter = 1 To 80
    Set imgNew = testFORM.Controls.Add("Forms.Image.1")
    With imgNew
        .Name = "Image" & imgNewCounter
        .Left = 24
        .Width = 20
        .Height = 10
        .BackColor = RGB(26, 25, 50)
        .Top = 5
    End With
Next
End Sub

使用 VBA 扩展性,您可以执行以下操作....

Sub CreateTextBox()

Dim vbp As VBProject
Dim vbc As VBComponent
Set vbp = Application.VBE.ActiveVBProject
Set vbc = vbp.VBComponents("Userform1")
vbc.Designer.Controls.Add "forms.textbox.1", "newcontrol"

End Sub

相关内容

最新更新