【发布时间】:2019-03-21 02:30:44
【问题描述】:
我已经尝试解决这个问题几天了,尽管谷歌搜索了很多,但我还是很卡住,所以非常感谢任何指点:)
所以我试图用另一个替换单词列表(我的文件是用于多个项目的模板)。它在文本框中工作得很好,但不适用于表格,所以我尝试将文本框代码调整为表格。下面的代码运行时没有给我一条错误消息,但仍然没有编辑我的表...
Sub Multi_FindReplace()
'PURPOSE: Find & Replace a list of text/values throughout entire PowerPoint presentation
Dim sld As Slide
Dim shp As Shape
Dim ShpTxt As TextRange
Dim TmpTxt As TextRange
Dim FindList As Variant
Dim ReplaceList As Variant
Dim x As Long
Dim i As Long
Dim j As Long
Dim tbl As Table
' INSERT THE LIST OF MERGE FIELDS HERE
FindList = Array("word1", "word2", "word3")
' INSERT THE LIST OF VARIABLES TO BE INSERTED BY HERE
ReplaceList = Array("word1.1", "word2.1", "word3.1")
'Loop through each slide in Presentation
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
'''''for tables
If shp.HasTable Then
'give name to table
Set tbl = shp.Table
'loops on table rows and columns
For i = 1 To shp.Table.Rows.Count
For j = 1 To shp.Table.Columns.Count
'Store cell text into a variable
ShpTxt = tbl.Cell(i, j).Shape.TextFrame.TextRange
'Ensure There is Text To Search Through
If ShpTxt <> "" Then
For x = LBound(FindList) To UBound(FindList)
'Store text into a variable
'Set ShpTxt = shp.TextFrame.TextRange
'Find First Instance of "Find" word (if exists)
Set TmpTxt = ShpTxt.Replace( _
FindWhat:=FindList(x), _
Replacewhat:=ReplaceList(x), _
WholeWords:=False)
'Find Any Additional instances of "Find" word (if exists)
Do While Not TmpTxt Is Nothing
Set ShpTxt = ShpTxt.Characters(TmpTxt.Start + TmpTxt.Length, ShpTxt.Length)
Set TmpTxt = ShpTxt.Replace( _
FindWhat:=FindList(x), _
Replacewhat:=ReplaceList(x), _
WholeWords:=False)
Loop
Next x
End If
Next j
Next i
Else
''''for all shapes excluding tables
If shp.HasTextFrame Then
'Store shape text into a variable
Set ShpTxt = shp.TextFrame.TextRange
'Ensure There is Text To Search Through
If ShpTxt <> "" Then
For x = LBound(FindList) To UBound(FindList)
'Store text into a variable
'Set ShpTxt = shp.TextFrame.TextRange
'Find First Instance of "Find" word (if exists)
Set TmpTxt = ShpTxt.Replace( _
FindWhat:=FindList(x), _
Replacewhat:=ReplaceList(x), _
WholeWords:=False)
'Find Any Additional instances of "Find" word (if exists)
Do While Not TmpTxt Is Nothing
Set ShpTxt = ShpTxt.Characters(TmpTxt.Start + TmpTxt.Length, ShpTxt.Length)
Set TmpTxt = ShpTxt.Replace( _
FindWhat:=FindList(x), _
Replacewhat:=ReplaceList(x), _
WholeWords:=False)
Loop
Next x
End If
End If
End If
Next shp
Next sld
End Sub
【问题讨论】:
-
你在哪里得到错误?
标签: arrays vba replace powerpoint