이 사이트의 일부 코드를 사용하여 Word 문서에서 키워드 검색을 수행하고 결과를 강조 표시하는 매크로를 만들었습니다.MS PowerPoint에서 텍스트 찾기 및 강조 표시
PowerPoint에서 효과를 복제하고 싶습니다.
다음은 Word 용 코드입니다.
Sub HighlightKeywords()
Dim range As range
Dim i As Long
Dim TargetList
TargetList = Array("keyword", "second", "third", "etc") ' array of terms to search for
For i = 0 To UBound(TargetList) ' for the length of the array
Set range = ActiveDocument.range
With range.Find ' find text withing the range "active document"
.Text = TargetList(i) ' that has the words from the array TargetList
.Format = True ' with the same format
.MatchCase = False ' and is case insensitive
.MatchWholeWord = True ' and is not part of a larger word
.MatchAllWordForms = False ' and DO NOT search for all permutations of the word
Do While .Execute(Forward:=True)
range.HighlightColorIndex = wdYellow ' highlight the keywords from the for loop yellow
Loop
End With
Next
End Sub
여기는 지금까지 PowerPoint에서 가지고있는 기능입니다. 작동하지 않습니다.
Sub HighlightKeywords()
Dim range As range
Dim i As Long
Dim TargetList
TargetList = Array("keyword", "second", "third", "etc") ' array of terms to search for
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) ' for the length of the array
With range.txtRng ' find text withing the range "shape, text frame, text range"
.Text = TargetList(i) ' that has the words from the array TargetList
.Format = True ' with the same format
.MatchCase = False ' and is case insensitive
.MatchWholeWord = True ' and is not part of a larger word
.MatchAllWordForms = False ' and DO NOT search for all permutations of the word
Do While .Execute(Forward:=True)
range.HighlightColorIndex = wdYellow ' highlight the keywords from the for loop yellow
Loop
End With
Next
End Sub
은 내가 MSDN을 통해 내 대답을 찾는 결국,하지만 나는 사람들이 제출 한 것과 같은 올바른 선택 대답에 매우 근접했다.
Sub Keywords()
Dim TargetList
Dim element As Variant
TargetList = Array("First", "Second", "Third", "Etc")
For Each element In TargetList
For Each sld In Application.ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasTextFrame Then
Set txtRng = shp.TextFrame.TextRange
Set foundText = txtRng.Find(FindWhat:=element, MatchCase:=False, WholeWords:=True)
Do While Not (foundText Is Nothing)
With foundText
.Font.Bold = True
.Font.Color.RGB = RGB(255, 0, 0)
End With
Loop
End If
Next
Next
Next element
End Sub
그 코드가 작동하지만 성능 악몽 밝혀 : 여기
내가 갔다 코드입니다. 아래에서 정답으로 선택한 코드는 훨씬 부드럽게 실행됩니다. 선택한 답변과 일치하도록 프로그램을 조정했습니다.
내가 생각해내는 것에 매우 가깝게 보입니다. 그래서 나는 올바른 방향으로 가고 있다고 생각합니다. 도와 주셔서 감사합니다! –
와우, 나는 당신에게 또 다른 +1을 줄 대표가 있었으면 좋겠다. 재미 있고 거룩한 코드로 코드를 컴파일 했으므로 내 것보다 10 배는 빠릅니다. 나는 당신의 for 루프가 중첩 된 모든 텍스트 박스에서 각 단어를 찾는 반복문과 한 단어에 대한 전체 프리젠 테이션을 검색하는 루프를 반복 한 다음 다음 단어에 대한 전체 프리젠 테이션을 다시 검색하는 것의 차이점이라고 생각합니다. 다시 한 번 감사드립니다. 귀하의 사례를 통해 효율성에 대해 많은 것을 배웠습니다. -Ryan –
기본적으로 필자가 사용한 방법 (PowerPoint 2013의 경우 어쨌든)은 Find() 함수가 일치하는 항목이 없을 때 Nothing을 반환하지 않고 빈 TextRange 개체를 대신 반환 할 수 있다는 것 . 이것은 PowerPoint 버그처럼 보입니다. 따라서 내 회피 코드는 Do not Not rngFound IsNothing 및 Alng rngFound.Length> 0과 동일합니다. – OfficeAddinDev