Powerpoint - 在组内的文本框中查找指定单词并添加评论
Powerpoint - find a specified word in a text box within a group and add a comment
我想在演示文稿中搜索指定的单词或短语,然后将评论添加到它出现的所有幻灯片。我有下面的代码,效果很好,但是我希望能够搜索成组的文本框(下面的代码只在文本框中搜索)
如有任何建议,我们将不胜感激。
Sub FindWordAndAddComment()
Dim sld As Slide
Dim shp As Shape
Dim txtRng As TextRange, rngFound As TextRange
Dim i As Long, n As Long
Dim TargetList
'enter or word phrase here
TargetList = Array("this is a test")
For Each sld In Application.ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasTextFrame Then
Set txtRng = shp.TextFrame.TextRange
For i = 0 To UBound(TargetList)
Set rngFound = txtRng.Find(TargetList(i))
Do While Not rngFound Is Nothing
n = rngFound.Start + 1
With sld.Comments.Add(12, 12, "found", "me", "'this is a test' has been found")
Set rngFound = txtRng.Find(TargetList(i), n)
End With
Loop
Next
End If
Next
Next
End Sub
这假定所有组都具有默认的“组”名称:
Dim sld As Slide
Dim shp As Shape
Dim txtRng As TextRange, rngFound As TextRange
Dim i As Long, n As Long
Dim TargetList(2) As String
Sub FindWordAndAddComment()
'enter or word phrase here
TargetList(0) = "This is a test"
TargetList(1) = "This is a text"
TargetList(2) = "Here we go"
For Each sld In Application.ActivePresentation.Slides
For Each shp In sld.Shapes
If InStr(shp.Name, "Group") <> 0 Then
For X = 1 To shp.GroupItems.Count
If shp.GroupItems(X).HasTextFrame Then
Set txtRng = shp.GroupItems(X).TextFrame.TextRange
FindTextAddComment
End If
Next X
Else
If shp.HasTextFrame Then
Set txtRng = shp.TextFrame.TextRange
FindTextAddComment
End If
End If
Next
Next
End Sub
Sub FindTextAddComment()
For i = 0 To UBound(TargetList)
Set rngFound = txtRng.Find(TargetList(i))
Do While Not rngFound Is Nothing
n = rngFound.Start + 1
With sld.Comments.Add(12, 12, "found", "me", "'this is a test' has been found")
Set rngFound = txtRng.Find(TargetList(i), n)
End With
Loop
Next
End Sub
我想在演示文稿中搜索指定的单词或短语,然后将评论添加到它出现的所有幻灯片。我有下面的代码,效果很好,但是我希望能够搜索成组的文本框(下面的代码只在文本框中搜索)
如有任何建议,我们将不胜感激。
Sub FindWordAndAddComment()
Dim sld As Slide
Dim shp As Shape
Dim txtRng As TextRange, rngFound As TextRange
Dim i As Long, n As Long
Dim TargetList
'enter or word phrase here
TargetList = Array("this is a test")
For Each sld In Application.ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasTextFrame Then
Set txtRng = shp.TextFrame.TextRange
For i = 0 To UBound(TargetList)
Set rngFound = txtRng.Find(TargetList(i))
Do While Not rngFound Is Nothing
n = rngFound.Start + 1
With sld.Comments.Add(12, 12, "found", "me", "'this is a test' has been found")
Set rngFound = txtRng.Find(TargetList(i), n)
End With
Loop
Next
End If
Next
Next
End Sub
这假定所有组都具有默认的“组”名称:
Dim sld As Slide
Dim shp As Shape
Dim txtRng As TextRange, rngFound As TextRange
Dim i As Long, n As Long
Dim TargetList(2) As String
Sub FindWordAndAddComment()
'enter or word phrase here
TargetList(0) = "This is a test"
TargetList(1) = "This is a text"
TargetList(2) = "Here we go"
For Each sld In Application.ActivePresentation.Slides
For Each shp In sld.Shapes
If InStr(shp.Name, "Group") <> 0 Then
For X = 1 To shp.GroupItems.Count
If shp.GroupItems(X).HasTextFrame Then
Set txtRng = shp.GroupItems(X).TextFrame.TextRange
FindTextAddComment
End If
Next X
Else
If shp.HasTextFrame Then
Set txtRng = shp.TextFrame.TextRange
FindTextAddComment
End If
End If
Next
Next
End Sub
Sub FindTextAddComment()
For i = 0 To UBound(TargetList)
Set rngFound = txtRng.Find(TargetList(i))
Do While Not rngFound Is Nothing
n = rngFound.Start + 1
With sld.Comments.Add(12, 12, "found", "me", "'this is a test' has been found")
Set rngFound = txtRng.Find(TargetList(i), n)
End With
Loop
Next
End Sub