将用户输入文本框中的文本放入另一张幻灯片上的文本框中

Place text from user input textbox into textbox on a different slide

如何从用户表单中的用户输入中获取文本以填充另一张幻灯片上的文本框?

我的 UserForm1 提交按钮代码:

Private Sub CommandButton1_Click()
    UserName$ = TextBox1.Value
    Unload UserForm1
    ActivePresentation.SlideShowWindow.View.Next
End Sub

我相信用户在 GUI 中键入的值存储在变量 UserName$ 中。

我试过使用标签框和文本框。

您的问题中有太多内容需要解压。 Microsoft 在通过 VBA 公开 PowerPoints 对象模型方面花费的精力最少。在 Access、Excel、Outlook 和 Word 中使用 VBA 时,您可以创建一些惊人的解决方案; PowerPoint,没那么多。

首先,按照 ashleedawg 的建议,您应该将 Option Explicit 添加到每个模块、Class 和表单代码。您可以通过单击工具(在菜单上)、selecting 选项,然后选中需要变量声明来将其设置为默认值。

现在创建一个模块,方法是单击菜单中的插入,然后单击 select 模块。这将创建一个新模块。在模块中,输入 Public UserName As String。现在,这将使变量 UserName 可以在整个解决方案中的任何位置访问。如果您愿意,它是一个全局变量。我通常调用一个包含我的 gobals 的模块 modGobals.

Option Explicit

Public UserName As String

现在输入表单代码。在幻灯片上创建文本框时,默认名称以 TextBox 开头,后跟 space 和一个数字。您将要重命名文本框。为此,请转到幻灯片视图。在功能区上,确保显示文件部分。在最右侧,您会看到一个名为“使用查找、替换、Select 进行编辑”的区域。单击 Select。从出现的下拉菜单中,单击 "Selection Pane..." selection 窗格将出现,您将看到幻灯片上的所有对象。当您单击不同的幻灯片对象时,它们将在 selection 窗格中突出显示。

现在您已将文本框重命名为 tbUserName 之类的名称,您可以更新代码,如下所示。

Option Explicit

Private pvSlide As Slide
Private pvShp As Shape

Private Sub CommandButton1_Click()

    UserName = TextBox1.Value

    'Assume that slide index 2 contains the text box you want to update
    Set pvSlide = ActivePresentation.Slides(2)

    'set the shape you're going to update
    Set pvShp = pvSlide.Shapes("tbUserName")

    'This is the fun part -- traversing the object tree to get to the
    'right property that so we can update the text box's value
    pvShp.TextFrame2.TextRange.Text = UserName

    Unload UserForm1
    'I'm not sure why you're executing this method.  So I commented it out
    'ActivePresentation.SlideShowWindow.View.Next

End Sub

当您 运行 用户表单,在文本框中输入文本并按下命令按钮时,您输入的文本将显示在幻灯片 2 的文本框中。

祝你好运,编码愉快

据我了解,您只是想修改之前的代码。 对于 $username = textBox1.value 下面的那个,写下:

yourtextBoxname.text = textBox1.text