我在powerpoint模块中成功使用了这个代码,但是当我在excel模块中移动它时,它给我带来了一些问题.我将Powerpoint应用程序嵌入到Excel的第1页.目标是从excel生成powerpoint,并在具有excel范围内新公司名称的powerpoint幻灯片上显示时替换公司名称.我得到错误429 ActiveX组件无法创建对象"For Each osld在ActivePresentation.Slides.我的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 …Run Code Online (Sandbox Code Playgroud)