在创建时使用vba中创建的表单

在创建时使用vba中创建的表单,vba,powerpoint,userform,Vba,Powerpoint,Userform,我用VBA编程创建了一个表单。我这样做是因为首先我使用另一种形式,根据我在第一种形式中设置的值,我必须使另一种形式变大或变小 我需要在单击第一个按钮时使用此表单。它出现了,我可以在文本框上写文本。。。但是,当我点击第二个表单的按钮时(我以编程方式完成的表单),我必须获取我编写的文本,但我使用MsgBox查看值,它似乎为空,我无法调试它,因为它是在进程已经启动时创建的代码。如果我再次执行此操作,因为现在它以正常形式存储,则会显示我写入的值 如何在第一次执行时获取这些值 下面是我创建的代码

我用VBA编程创建了一个表单。我这样做是因为首先我使用另一种形式,根据我在第一种形式中设置的值,我必须使另一种形式变大或变小

我需要在单击第一个按钮时使用此表单。它出现了,我可以在文本框上写文本。。。但是,当我点击第二个表单的按钮时(我以编程方式完成的表单),我必须获取我编写的文本,但我使用MsgBox查看值,它似乎为空,我无法调试它,因为它是在进程已经启动时创建的代码。如果我再次执行此操作,因为现在它以正常形式存储,则会显示我写入的值

如何在第一次执行时获取这些值

下面是我创建的代码

       'Create the UserForm
        Set TempForm = ActivePresentation.VBProject.VBComponents.Add(vbext_ct_MSForm)


        'Set Properties for TempForm
        With TempForm
            .Properties("Caption") = "Possible answers"
            .Properties("Width") = 300
            .Properties("Height") = 10 + 34 * choiceNum + 50
        End With
        FormName = TempForm.Name

        For i = 1 To choiceNum

            Set newTab = TempForm.Designer.Controls.Add("Forms.Label.1", "label" & i, True)
            With newTab
                .Caption = "Answer" & i
                .width = 40
                .height = 15
                .top = 10 + 30 * (i - 1)
                .left = 10
            End With

            Set cCntrl = TempForm.Designer.Controls.Add("Forms.TextBox.1", "textBox" & i, True)
            With cCntrl
                .width = 150
                .height = 15
                .top = 10 + 30 * (i - 1)
                .left = 60
                .ZOrder (0)
            End With
        Next i

        Set NewButton = TempForm.Designer.Controls.Add("forms.CommandButton.1", "answerButton", True)
        With NewButton
            .Caption = "Create survey"
            .left = 60
            .top = 30 * choiceNum + 10
        End With
        'X = ActivePresentation.VBProject.VBComponents(FormName).CodeModule.CountOfLines
        With TempForm.CodeModule
          X = .CountOfLines + 1
            .InsertLines X + 1, "Sub answerButton_Click()"
            .InsertLines X + 2, "   Dim cSlide As Slide"
            .InsertLines X + 3, "  Dim survey As Shape"
            .InsertLines X + 4, "  Dim top As Integer"
            .InsertLines X + 5, "   Set cSlide = Application.ActiveWindow.View.Slide"
            .InsertLines X + 6, "   top = 30"
            .InsertLines X + 7, "   "
            .InsertLines X + 8, "   For i = 1 To surveyCreation.choNum"
            .InsertLines X + 9, "   "
            .InsertLines X + 10, "   top = top + 15"
            .InsertLines X + 11, "   Set survey = cSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, 30, top, 400, 10)"
            .InsertLines X + 12, "   survey.TextFrame.TextRange.text = UserForm1.Controls(i * 2 - 1).Text"
            .InsertLines X + 13, "   MsgBox ""this is the result: "" & UserForm1.Controls(i * 2 - 1).Text"
            .InsertLines X + 14, "   survey.TextFrame.TextRange.ParagraphFormat.Bullet = True"
            .InsertLines X + 15, "   survey.TextFrame.TextRange.ParagraphFormat.Bullet.Type = ppBulletUnnumbered"
            .InsertLines X + 16, "  survey.Select Replace:=False"
            .InsertLines X + 17, "  Next i"
            .InsertLines X + 18, "  With ActiveWindow.Selection.ShapeRange"
            .InsertLines X + 19, "  .Group.title = ""Dink survey creation"" & surveyCreation.typ"
            .InsertLines X + 20, "End With"
            .InsertLines X + 21, "End Sub"
        End With

       VBA.UserForms.Add(FormName).Show

希望我能解释清楚。

为什么要在UserForm1.Controlsi*2-1.Text中使用UserForm1?每次添加表单时,它都会有不同的名称。试试这个我。控制。谢谢你解决了我的问题。我使用UserForm1是因为它是默认创建的名称,当您再次执行表单时,它正在工作,所以这是名称,但在创建时,名称可能还没有默认设置。反正现在已经解决了!: