如何用 activeX 文本框值替换 Powerpoint 中的文本?

发布于 2025-01-13 04:43:15 字数 711 浏览 1 评论 0原文

如果我不能很好地解释这一点,我很抱歉。语言障碍等等。可能会解释为什么我无法用谷歌搜索解决方案......无论如何。 我正在尝试制作一个交互式 Powerpoint,在第一张幻灯片中,用户在 ActiveX 文本框中写入他们的姓名,然后在其他几张幻灯片中重复该名称。因为名称将位于不同文本的中间,所以我的解决方案是添加一个占位符单词,然后将其替换为文本框值。我能够为弗兰肯斯坦编写一种代码,将一个名称替换为另一个名称,该代码运行良好,但我无法让文本框使用它。我能做的最好的事情就是用 TextBox1.Value 的某些变体替换占位符名称,虽然我知道导致该问题的原因,但我无法找到解决方案。 不确定它是否有什么不同,但计划是在运行宏的活动文本框旁边添加某种“确定”按钮。

Sub Findandreplace()
Dim sld As Slide
Set sld = ActivePresentation.Slides(1)
Dim shp As Shape
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "word1", "word2")
End If
End If
Next shp
Next sld
End Sub

I'm sorry if I can't explain this very well. Language barrier and all that. Might explain why I wasn't able to google a solution... Anyway.
I'm trying to make an interactive Powerpoint where in the first slide the user writes their name in an ActiveX textbox and the name then repeats in several other slides. Because the name would be in the middle of different texts my solution was to add a placeholder word that would then be replaced with the textbox value. I was able to Frankenstein a code that replaces one name with another that works well enough but I can't get the textbox to work with it. Best I can do is replace the placeholder name with some variation of TextBox1.Value and while I know what causes that issue I can't work out a solution.
Not sure if it makes a difference but the plan is to add some sort of "OK" button next to the active textbox that runs the macro.

Sub Findandreplace()
Dim sld As Slide
Set sld = ActivePresentation.Slides(1)
Dim shp As Shape
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "word1", "word2")
End If
End If
Next shp
Next sld
End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撕心裂肺的伤痛 2025-01-20 04:43:15

ActiveX 对象具有与常规 PPT 形状不同的一组属性/方法。假设您在变量 oSh 中引用了 AX 文本框,

osh.OLEFormat.Object.Text

将为您提供 ActiveX 文本框中的文本

ActiveX objects have a different set of properties/methods than regular PPT shapes. Assuming you have a reference to the AX textbox in a variable oSh,

osh.OLEFormat.Object.Text

will give you the text in the ActiveX textbox

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文