【发布时间】:2012-03-21 19:43:29
【问题描述】:
我在一个 powerpoint odule 中成功使用了这段代码,但是当我将它移动到我的 excel 模块中时,它给了我几个问题。我在 Excel 的表 1 上嵌入了 Powerpoint 应用程序。目标是从 excel 生成 powerpoint,并在其出现在 powerpoint 幻灯片上时将公司名称替换为 excel 范围内的新公司名称。 我收到错误 429 ActiveX 组件无法在“为 ActivePresentation.Slides 中的每个 osld 创建对象。我的 Powerpoint 演示文稿是否不活动?任何帮助将不胜感激。使用 excel/Powerpoint 2010。
Sub changeme(sFindMe As String, sSwapme As String)
Dim osld As Slide
Dim oshp As Shape
Dim otemp As TextRange
Dim otext As TextRange
Dim Inewstart As Integer
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.HasTextFrame Then
If oshp.TextFrame.HasText Then
Set otext = oshp.TextFrame.TextRange
Set otemp = otext.Replace(sFindMe, sSwapme, , msoFalse, msoFalse)
Do While Not otemp Is Nothing
Inewstart = otemp.Start + otemp.Length
Set otemp = otext.Replace(sFindMe, sSwapme, Inewstart, msoFalse, msoFalse)
Loop
End If
End If
Next oshp
Next osld
End Sub
'-------------------------------------------------------------------------
Sub swap()
Dim sFindMe As String
Dim sSwapme As String
Dim ppApp As PowerPoint.Application
Dim ppPreso As PowerPoint.Presentation
'Start Powerpoint
'Look for existing instance
On Error Resume Next
Set ppApp = GetObject(, "PowerPoint.Application")
On Error Goto 0
'Create new instance if no instance exists
Set ppApp = CreateObject("Powerpoint.Application")
'Open Template in word
With Sheets("Sheet1").Shapes("Object 1").OLEFormat.Verb(Verb:=xlVerbOpen)
End With
'Make it visible
ppApp.Visible = True
sFindMe = "Name To Find"
'change this to suit
sSwapme = "New Name"
Call changeme(sFindMe, sSwapme)
'sFindMe = "<find2>"
'sSwapme = ActivePresentation.Slides(1).Shapes(2).TextFrame.TextRange
'Call changeme(sFindMe, sSwapme)
End Sub
【问题讨论】:
-
您的 ppt 在 Excel 中 - 您需要在引用 ActivePresentation 时包含
ppApp引用:即。ppApp.ActivePresentation.Slides