none
PowerPoint: improved macro RRS feed

  • Question

  • can you improve this macro in order to ask which word to search ( only for one word would be ok) and when found change font color to  white  and same text box background invisible. That should work in PP

    Sub HighlightKeywords()
        Dim sld As Slide
        Dim shp As Shape
        Dim txtRng As TextRange, rngFound As TextRange
        Dim i As Long, n As Long
        Dim TargetList

        '~~>  Array of terms to search for
        TargetList = Array("test")

        '~~> Loop through each slide
        For Each sld In Application.ActivePresentation.Slides
            '~~> Loop through each shape
            For Each shp In sld.Shapes
                '~~> Check if it has text
                If shp.HasTextFrame Then
                    Set txtRng = shp.TextFrame.TextRange

                    For i = 0 To UBound(TargetList)
                        '~~> Find the text
                        Set rngFound = txtRng.Find(TargetList(i))

                        '~~~> If found
                        Do While Not rngFound Is Nothing
                            '~~> Set the marker so that the next find starts from here
                            n = rngFound.Start + 1
                            '~~> Change attributes
                            With rngFound.Font
                                .Bold = msoTrue
                                .underline = msoTrue
                                .Italic = msoTrue
                                '~~> Find Next instance
                                Set rngFound = txtRng.Find(TargetList(i), n)
                            End With
                        Loop
                    Next
                End If
            Next
        Next
    End Sub

    Thanks


    Wednesday, July 23, 2014 3:59 AM

All replies

  • Macro?

    Macros are used with Micrsoft Office applications aren't they?

    What is Array in your "Macro"? I don't see Array instantiated anywhere.

    If this Macro is in fact a Macro for an Office applictation and not a sub for a VB.Net application then you need to post your question in a forum for Office about Macros somewhere IMO.


    La vida loca

    Wednesday, July 23, 2014 5:05 AM
  • sorry

    Wednesday, July 23, 2014 9:14 PM
  • Hi,

    >>can you improve this macro in order to ask which word to search ( only for one word would be ok) and when found change font color to  white  and same text box background invisible.<<

    If you want to make this function to reuse, you can extract the search word as a parameter. To search only a word rather than a array, you can replace it with a string. Also we can change the font color by Font Object. What do you mean make same text box background invisible? Did you want to set the shape fil with No Fill like fingure below:

    If yes, we can set the FillFormat.BackColor to achieve the goal. Here is a sampe for your reference:

    Sub HighlightKeywords(searchTxt As String)
         Dim sld As Slide
         Dim shp As Shape
         Dim txtRng As TextRange, rngFound As TextRange
         Dim i As Long, n As Long
         Dim TargetList
    
       '~~> Loop through each slide
         For Each sld In Application.ActivePresentation.Slides
             '~~> Loop through each shape
             For Each shp In sld.Shapes
                 '~~> Check if it has text
                 If shp.HasTextFrame Then
                     Set txtRng = shp.TextFrame.TextRange
    
                  
                         '~~> Find the text
                         Set rngFound = txtRng.Find(searchTxt)
    
                         '~~~> If found
                         Do While Not rngFound Is Nothing
                             '~~> Set the marker so that the next find starts from here
                             n = rngFound.Start + 1
                             shp.Fill.BackColor.RGB = RGB(255, 255, 255)
                             '~~> Change attributes
                             With rngFound.Font
                                 .Color.RGB = RGB(255, 255, 255)
                                 '~~> Find Next instance
                                 Set rngFound = txtRng.Find(searchTxt, n)
                             End With
                         Loop
                  
                 End If
             Next
         Next
     End Sub
    
    
    
    
    

    Here are some helpful links for you learning Powerpoint Developing:
    Welcome to the PowerPoint 2013 developer reference

    How do I... (PowerPoint 2013 developer reference)

    Bset regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, July 24, 2014 2:41 AM
    Moderator