Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用VBA在PowerPoint中添加搜索栏,搜索用户在特定幻灯片中输入的单词并突出显示?_Vba_Powerpoint - Fatal编程技术网

使用VBA在PowerPoint中添加搜索栏,搜索用户在特定幻灯片中输入的单词并突出显示?

使用VBA在PowerPoint中添加搜索栏,搜索用户在特定幻灯片中输入的单词并突出显示?,vba,powerpoint,Vba,Powerpoint,我希望在我的演示文稿中添加一个搜索栏,搜索用户在特定幻灯片中输入的特定单词并突出显示。这个词将有一个超链接连接到它,它将带到这个词的含义 我是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 Boolea

我希望在我的演示文稿中添加一个搜索栏,搜索用户在特定幻灯片中输入的特定单词并突出显示。这个词将有一个超链接连接到它,它将带到这个词的含义

我是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

谢谢你发布你的代码;此外,您应该解释它到底有什么问题。它没有编译,它做了错误的事情,它没有做任何事情?我假设这应该在幻灯片放映视图中运行,并且其中一张幻灯片上有一个文本框。这对你来说可能是显而易见的,但对整个世界来说却不是。最好先把事情弄清楚,为大家节省一些时间

试试这个。注意,它只会在给定的文本范围内找到问题单词的第一个实例

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
   sTextToFind = Me.TextBox1.Text
     'For Each osld In Application.ActivePresentation.Slides(5)
    For Each oshp In ActivePresentation.Slides(5).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))
                    SlideShowWindows(1).View.GotoSlide (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

代码的问题在于Application.ActivePresentation.Slides5中的每个osld都显示错误。我想要的是,假设第5张幻灯片中有20个单词,我希望这个搜索栏位于第1张幻灯片中,用户可以使用它搜索这20个单词中的任何一个。是的,我假设这会引发错误。看看重写的版本,它工作得很好。非常感谢。如果我有任何其他问题,有没有办法直接联系到你?在这里再发一篇帖子会更好。我定期在这里登记。