【发布时间】:2017-03-09 04:50:51
【问题描述】:
我希望在我的演示文稿中添加一个搜索栏,用于搜索用户在特定幻灯片中输入的特定单词并突出显示它。该词将附有一个超链接,可以将其理解为该词的含义。
我是 VBA 的新手。我有此代码,需要进行必要的更改才能使其正常工作。
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim osld As Slide
Dim oshp As Shape
Dim b_found As Boolean
Dim oTxtRng As TextRange
Dim sTextToFind As String
sTextToFind = Me.TextBox1.Text
If KeyCode = 13 Then 'ENTER PRESSED
If Me.TextBox1.Text <> "" Then
For Each osld In Application.ActivePresentation.Slides(5)
For Each oshp In osld.Shapes
If oshp.HasTextFrame Then
If oshp.TextFrame.HasText Then
If InStr(UCase(oshp.TextFrame.TextRange), UCase(Me.TextBox1.Text)) > 0 Then
SlideShowWindows(1).View.GotoSlide (osld.sectionIndex(5))
Set oTxtRng = oshp.TextFrame.TextRange.Characters(InStr(oshp.TextFrame.TextRange.Text, sTextToFind), Len(sTextToFind))
Debug.Print oTxtRng.Text
With oTxtRng
.Font.Bold = True
End With
b_found = True
Exit For
End If
End If
End If
Next oshp
If b_found = True Then Exit For
Next osld
End If
If b_found = False Then MsgBox "Not found"
End If
End Sub
【问题讨论】:
标签: vba powerpoint