【发布时间】:2020-03-05 17:57:54
【问题描述】:
我有一个 VBA 代码,它应该在 powerpoint 中用另一个词替换一个词。然而,当我尝试运行它时,我收到错误 429“ActiveX 组件无法创建对象”,但我不知道为什么。这是代码:
Sub pres()
Dim PowerPointApp As Object
Set PowerPointApp = CreateObject("PowerPoint.Application")
Dim myPres As Object
Set myPres = PowerPointApp.Presentations.Open("C:\Users\NAME\Desktop\PRESVBA\Pres.pptx")
Dim sld As Slide
Set sld = ActivePresentation.Slides(3)
Dim shp As Shape
For Each shp In sld.Shapes
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Montant", "Amount")
End If
End If
Next shp
End Sub
【问题讨论】:
-
这个错误出现在哪一行?你有PPT吗?
-
在 Set sld = ActivePresentation.Slides(3) 行,我有 Powerpoint,它打开了正确的文件,但我得到了错误
-
你打开的PowerPoint中有3张幻灯片吗?
-
不,代码应该改变幻灯片编号 3 的文字
-
你需要在前面加上
ActivePresentation.Slides(3)你的powerpointapp