VBA Powerpoint - find HIGHLIGHTED text in shape, then ADD a new text box with ANIMATION effect

Anonymous
2020-05-20T03:02:27+00:00

I have this Powerpoint file. Here the link:

https://drive.google.com/open?id=1JaRrBDOEKkCnxeGHrynwdmhPtaOZ8Y4f

I have turned a MS Word file into Powerpoint file using the instruction in this video:

https://www.youtube.com/watch?v=7oao6EzF08U

I want to unhighlight the text, then add a new text box (Red shape fill and Send behind text) with ANIMATION effect, put it in the position of the unhighlighted text like in the pictures.

Therefore, I can show the correct answer to my students when teaching using PPT.

I have about 100 slides like this but I don't have enough time to do it all manually.

Unfortunately, MS Powerpoint doesn't have Macro Recorder like in MS Word and I also don't know much about VBA code.

Is there any way to use VBA code to solve this problem?

Thanks in advance.

Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Anonymous
    2020-05-22T14:50:08+00:00

    I'm assuming you have 365 or 2019 because 206 doesn't support highlights in PPT.

    To the best of my knowledge it is not possible to remove highlights correctly with vba but you could try this code to Add Red Shapes

    Sub AddShape()

    Dim osld As Slide

    Dim oshp As Shape

    Dim oshp2 As Shape

    Dim otr2 As TextRange2

    Dim P As Long

    Dim BL As Long

    Dim BR As Long

    Dim BW As Long

    Dim BH As Long

    Dim ZOP As Long

    For Each osld In ActivePresentation.Slides

    For Each oshp In osld.Shapes

    If oshp.HasTextFrame Then

    If oshp.TextFrame2.HasText Then

    Set otr2 = oshp.TextFrame2.TextRange

    For P = 1 To otr2.Paragraphs.Count

    If otr2.Paragraphs(P).Font.Highlight.RGB <> 0 Then

    BL = otr2.Paragraphs(P).BoundLeft

    BT = otr2.Paragraphs(P).BoundTop

    BW = otr2.Paragraphs(P).BoundWidth

    BH = otr2.Paragraphs(P).BoundHeight

    ZOP = oshp.ZOrderPosition

    End If

    Next P

    End If

    End If

    Next oshp

    If BL>0 Then

    Set oshp2 = osld.Shapes.AddShape(msoShapeRectangle, BL, BT, BW, BH)

    oshp2.Fill.ForeColor.RGB = vbRed

    Do

    oshp2.ZOrder (msoSendBackward)

    Loop Until oshp2.ZOrderPosition < ZOP

    osld.TimeLine.MainSequence.AddEffect oshp2, msoAnimEffectAppear

    End If

    BL=0

    Next osld

    End Sub

    Once done you could kill the highlights by choosing OUTLINE view, select all the text in the outline pane and choose No Highlight color.

    WORK ON A COPY!

    0 comments No comments

6 additional answers

Sort by: Most helpful
  1. John Korchok 224.4K Reputation points Volunteer Moderator
    2020-05-20T18:37:08+00:00

    Your request isn't clear. Is the student applying a highlight to the text they think is correct? Or do you highlight the text? Why not just change the highlight color instead of drawing a box behind it? Getting the position of the highlighted text and placing a box there makes the VBA more complex than changing the color of the highlight.

    0 comments No comments
  2. Anonymous
    2020-05-21T02:22:44+00:00

    Your request isn't clear. Is the student applying a highlight to the text they think is correct? Or do you highlight the text? Why not just change the highlight color instead of drawing a box behind it? Getting the position of the highlighted text and placing a box there makes the VBA more complex than changing the color of the highlight.

    The highlighted text is not supposed to show up when I first show it to the student.

    First, students will see the whole question without answer, then I will show the answer key (which is the drawing box). If I highlight the text from the start, then my students will see the answer right away without thinking of the answer to it.

    0 comments No comments
  3. John Korchok 224.4K Reputation points Volunteer Moderator
    2020-05-21T16:01:48+00:00

    Please explain the role of the highlight. Is this just something you have used to illustrate the issue, or does the highlight actually appear in the process of the student answering the question? How does the student indicate which item they think is the answer?

    0 comments No comments
  4. Anonymous
    2020-05-21T18:37:54+00:00

    As JohnK says it's not really clear but maybe ...

    You already have the test with highlighted answers and want to change it to a similar presentation with mock highlights that appear on click to show the answer?

    Maybe JohnK knows different (he's a smart cookie) but Highlights are not well supported in the vba objct model in my experience and it may not be straightforward to do what you need with vba.

    0 comments No comments