【问题标题】:Error in batch find and replace VBA code for Power Point slides批量查找和替换 Power Point 幻灯片的 VBA 代码时出错
【发布时间】:2017-05-30 12:06:07
【问题描述】:

我正在尝试为 VBA 中的 Power Point 幻灯片编写 batch find and replace 代码,但出现以下错误:Compile Error Method or data member not found

调试器正在突出显示 PP.Shapes 在线 13 中的形状。

我对VBA没有太多经验。我从以下方面收集了想法:
* Getting Started with VBA in PowerPoint 2010 (Office 开发中心)
* Power Point VBA-Find & Replace (YouTube)
* “从文件导入幻灯片的简单宏”@(VBA Express 论坛)

Sub BatchFindReplace()
Dim shp As Shape
Dim strFileName As String
Dim strFolderName As String
Dim PP As Presentation
'Directory
strFolderName = "C:\Users\Emma\Desktop\temp1"
strFileName = Dir(strFolderName & "\*.ppt*")
Do While Len(strFileName) > 0
Set PP = Presentations.Open(strFolderName & "\" & strFileName)

'Find and Replace Code
For Each shp In PP.Shapes
If shp.HasTextFrame Then
    If shp.TextFrame.HasText Then
        shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "W", "kkk")
    End If
End If
Next

PP.Close
strFileName = Dir
Loop
End Sub

【问题讨论】:

  • VBA 标签将涵盖所有 MS-Office 应用程序。您不必标记所有这些 :)
  • 哦,好的,我明白了:)。

标签: vba powerpoint


【解决方案1】:

属性.Shapes 不是Presentation 的成员,而是Slide 的成员

'~~> Open the relevant powerpoint file
Set PP = Presentations.Open(strFolderName & "\" & strFileName)

'~~> Change this to the relevant slide which has the shape
Set PPSlide = PP.Slides(1)

For Each shp In PPSlide.Shapes
    Debug.Print shp.Name
Next shp

如果您想处理所有幻灯片中的所有形状,则必须循环播放幻灯片。

Dim sld As Slide

'~~> Open the relevant powerpoint file
Set PP = Presentations.Open(strFolderName & "\" & strFileName)

For Each sld In PP.Slides
    For Each shp In sld.Shapes
        Debug.Print shp.Name
    Next shp
Next

【讨论】:

  • 有了你的解决方案,我现在有了一个有效的 vba 代码 :) :link@Siddharth Rout
猜你喜欢
  • 1970-01-01
  • 2016-05-17
  • 1970-01-01
  • 1970-01-01
  • 2021-12-28
  • 2016-10-21
  • 2020-12-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多