我试图在batch find and replace
中为Power Point幻灯片编写VBA
代码,但我收到以下错误:Compile Error Method or data member not found
。
< BR />
调试器突出显示PP.Shapes
行13
中的形状。
我对VBA没有多少经验。我收集了以下想法:
* Getting Started with VBA in PowerPoint 2010(Office开发中心)
* Power Point VBA-Find & Replace(YouTube)
*&#34;简单宏从文件导入幻灯片&#34; @(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
答案 0 :(得分: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