PowerPoint has evolved into an app which is the Swiss Army knife of content creation, not only for presentations but also printed collaterals, videos and even interactive presentations.
In this second part of our series on supercharging PowerPoint interactive presentations with VBA we look at how you can provide your users with visual feedback for active areas of your slide using a mouse hover technique.
In part 1 you learned how you can add links to objects on slides that, when clicked, take the user to a different slide. But how does the user know that the object you’ve created the link for is an active object on your slide? In other words, how do they know it is clickable?
Good design plays an important part here. If you look at the slide below, it’s fairly obvious that the items in the left hand menu might do something:
However, in the next example, it’s not immediately clear that the three icons, or their corresponding text boxes link to other parts of the presentation:
You can add built-in PowerPoint visual feedback for the user by selecting the linked object and clicking the Insert tab in PowerPoint. Then, in the Links group click the Action button. As you discovered in Part 1, this opens the window below where you can set up your desired link in the Mouse Click tab. For the visual feedback you click the second Mouse Over tab and check the Highlight when mouse over option:
Now when you hover your mouse over the active area in slide show mode you can see which content elements are active:
In the example above, the mouse is hovered over the icon of the ship. Can you tell it’s an active object with a hyperlink? That very faint green dotted line is what PowerPoint uses by default. It’s not very clear at all is it? You might even say it’s pretty ugly! Not what you want for your interactive presentations.
You can do much better with VBA
VBA: Highlighting active objects in interactive presentations
You can use our custom VBA macro to do something much smarter:
Public Sub GraphicHover(ByRef oGraphic As Shape)
oGraphic.Fill.ForeColor.ObjectThemeColor = msoThemeColorAccent1
End Sub
You can probably work out that this macro changes the fill colour of the object (called a Shape in VBA) to Accent 1 from the theme. Once you’ve added this to your PowerPoint file (read this to find out how) then you can uncheck the PowerPoint highlighting feature and instead assign the Mouse Over event to Runmacro, selecting the GraphicHover macro:
Now when you move the mouse over the icon during a slide show the fill colour changes:
But as you can see at the end of the video there’s a major problem. When you move away from the icon, it doesn’t return to its original state.
What you need here is a Mouse Out event in the Actions window.
Spoiler alert, it’s not there! But don’t worry, with some out-of-the-box thinking there’s a clever hack to overcome this. What you need to do is to create an invisible shape which resets the hover state of the icon as you hover over this invisible shape. Here are the steps to create your invisible shape:
First make sure you’re using a shape for the icon that can be filled e.g. an SVG icon or a PowerPoint vector shape (a PNG/JPG picture won’t work)
Add our ResetGraphicHover macro from the code snippet below to your PowerPoint VBA project (read this to find out how)
Insert a rectangle, sized and positioned to cover the whole slide
From the Insert tab, click the Action button and set the Mouse Over event on the rectangle to run our macro ResetGraphicHover
Right-click the rectangle and then click Format Shape…
In the Format Shape pane, set the Fill / Transparency slider to 100% (don’t set it to No fill) and set the Line to No Line
Send it to the back by clicking the Home tab followed by Arrange and Send to Back
Tip: to prevent this rectangle from getting deleted, moved or interfering with the editing of your slide, you can create it on a slide master layout instead.
Here’s the code for the reset hover macro:
Public Sub ResetGraphicHover(ByRef oCover As Shape)
Dim oSld As Slide
Dim oShp As Shape
Set oSld = oCover.Parent
For Each oShp In oSld.Shapes
With oShp.Fill.ForeColor
If .ObjectThemeColor = msoThemeColorAccent1 Then .ObjectThemeColor = msoThemeColorDark1
End With
Next
End Sub
Now when you run the interactive presentation, the icon fill colour changes as you hover over it and resets when you hover away from it, triggered as you hover over the invisible cover shape:
That’s much clearer visual feedback. You can go further and set all sorts of other properties in the hover and reset macros such as outline colour, transparency, line weights and so on:
Now that you know how to use VBA when creating interactive presentations, have a read of this post on restoring default slide master layouts with VBA or discover our Click-and-Explore service to find out how we can help create beautifully-designed interactive presentations for you.
As the saying goes, a picture speaks a thousand words. PowerPoint offers you multiple image sources to help you create your latest presentation masterpiece, but it isn't very consistent in how it presents them to you. Let's fix that!
How do you make sure that your graphs and charts have consistent branding across Excel, PowerPoint and Word? Learn how to create and use custom templates that support your brand identity across Microsoft Office.
You can do some really cool things in Microsoft Office with just a few lines of Visual Basic for Applications (VBA) - from creating your own custom formula in Excel to correcting branded content in PowerPoint to merging address data for a mail campaign in Word. And sometimes you need to share that VBA solution with colleagues and clients, via the Internet. A change that Microsoft rolled out at the end of March 2022 tweaks the process required by Windows users to gain access to this active content.
Hi thanks for the great insight once again. In addition to a question that I posed in the introduction blog about using a Mousedown function, as opposed to a mouse click, I have used the above to better highlight menu navigation buttons which looks great, however, as it is used to navigate to and from other slides I find that the button highlight cover / fill color used whilst hovering over the buttons has a memory and as you do not move off the button the reset hover is not triggered, can you assist with how to reset this given I do not think it is the same as resetting the slide animation as explained on Supercharging PowerPoint interactive presentations with VBA (Part 1) which I also tried. Much appreciated
Hi Simon. That’s a good point! You could have two macros for a given shape, one set to run on Mouse Over to do the highlighting and the other on Mouse Click to reset the shape’s style and go to the desired slide/URL etc. Note that because you want to perform a custom action on click that you need to code the macro to do the hyperlinking rather than using the standard PowerPoint interface. Try setting this as the mouse click macro as a good place to start:
Public Sub ShapeClick(ByRef oShp As Shape) ResetGraphicHover oShp ActivePresentation.SlideShowWindow.View.GotoSlide 2 End Sub
Hi there, i have this presentation (PPT) in which i have several hyperlinks, both as mouse clicks and mouse overs. Now when i view the slide show or export it as a PPS (powerpoint show) i see the hover animations, however when i export to PDF i dont get any of the animations, but i do get the hyperlinks that are mouse clicks. Is there any code for the hover/mouse over effect to be seen on the PDF like an interactive document. Please help.
Hi Sunil. Converting to PDF will lose your animations, transitions and any embedded code. Are you using PDF to lock down your presentation, reduce its file size or something else? If the first, you could distribute or as a password protected read only file to convert it to video (no code) or simply save as a ppsm file.
I was able to get the initial color change working great when I hover over my initial shape. I am trying to have it change back when I hover over the transparent shape I am using but I am not having any luck on having it change back? Any idea on why this may be happing?
Hi Justin. Have you set the mouse over event for the transparent shape to fire the reset macro? Is the reset macro firing? You can add a breakpoint in the reset macro to check by clicking in the margin of the code module (a red dot will appear). If the macro is firing the VBE window will appear at your breakpoint.
Hey Jamie, it looks like the reset macro is firing. I tried setting the transparency on my reset rectangle shape to 50% to see if anything was happening to it when the reset macro was firing. Instead of switching my original shape back to it’s original color, it only changed the reset rectangle I created to a dark grey color. Would you be open to connecting with me on this? I would be happy to hire you to help consult me through this piece of my project.
Thanks for this great tip. I was wondering what part of the coding needs to change if I just wanted to change the text colour as opposed to the Shape Fill?
Hi Claire and thanks for a great question. You can access the font colour in the PowerPoint OM (Object Model) via Shape.TextRange.TextFrame.Font.Color and at that level, you can either set the RGB property to a fixed colour value or use a theme-based colour via the ObjectThemeColor property.
Will this work using inserted jpeg images instead of shapes made within powerpoint?
I am trying to make a gallery, with each thumnail image being the button to a separate slide with more info about the image. I got the links to work, but not the mouse over effect. I really don’t want to have to use the dotted green line, so any help would be greatly appreciated.
I wanted to make sure I send you both a HUGE thank you for making this story come to life and creating amazing graphics to help. We really appreciate BrightCarbon for stepping up our presentation game massively!
Hi thanks for the great insight once again. In addition to a question that I posed in the introduction blog about using a Mousedown function, as opposed to a mouse click, I have used the above to better highlight menu navigation buttons which looks great, however, as it is used to navigate to and from other slides I find that the button highlight cover / fill color used whilst hovering over the buttons has a memory and as you do not move off the button the reset hover is not triggered, can you assist with how to reset this given I do not think it is the same as resetting the slide animation as explained on Supercharging PowerPoint interactive presentations with VBA (Part 1) which I also tried. Much appreciated
Hi Simon. That’s a good point! You could have two macros for a given shape, one set to run on Mouse Over to do the highlighting and the other on Mouse Click to reset the shape’s style and go to the desired slide/URL etc. Note that because you want to perform a custom action on click that you need to code the macro to do the hyperlinking rather than using the standard PowerPoint interface. Try setting this as the mouse click macro as a good place to start:
Public Sub ShapeClick(ByRef oShp As Shape)
ResetGraphicHover oShp
ActivePresentation.SlideShowWindow.View.GotoSlide 2
End Sub
Hi there, i have this presentation (PPT) in which i have several hyperlinks, both as mouse clicks and mouse overs. Now when i view the slide show or export it as a PPS (powerpoint show) i see the hover animations, however when i export to PDF i dont get any of the animations, but i do get the hyperlinks that are mouse clicks. Is there any code for the hover/mouse over effect to be seen on the PDF like an interactive document. Please help.
Hi Sunil. Converting to PDF will lose your animations, transitions and any embedded code. Are you using PDF to lock down your presentation, reduce its file size or something else? If the first, you could distribute or as a password protected read only file to convert it to video (no code) or simply save as a ppsm file.
I was able to get the initial color change working great when I hover over my initial shape. I am trying to have it change back when I hover over the transparent shape I am using but I am not having any luck on having it change back? Any idea on why this may be happing?
Hi Justin. Have you set the mouse over event for the transparent shape to fire the reset macro? Is the reset macro firing? You can add a breakpoint in the reset macro to check by clicking in the margin of the code module (a red dot will appear). If the macro is firing the VBE window will appear at your breakpoint.
Hey Jamie, it looks like the reset macro is firing. I tried setting the transparency on my reset rectangle shape to 50% to see if anything was happening to it when the reset macro was firing. Instead of switching my original shape back to it’s original color, it only changed the reset rectangle I created to a dark grey color. Would you be open to connecting with me on this? I would be happy to hire you to help consult me through this piece of my project.
Hi Justin. If you drop an email to us via our contact form mentioning my name I’ll be happy to connect with you.
Thanks for this great tip. I was wondering what part of the coding needs to change if I just wanted to change the text colour as opposed to the Shape Fill?
Hi Claire and thanks for a great question. You can access the font colour in the PowerPoint OM (Object Model) via Shape.TextRange.TextFrame.Font.Color and at that level, you can either set the RGB property to a fixed colour value or use a theme-based colour via the ObjectThemeColor property.
Will this work using inserted jpeg images instead of shapes made within powerpoint?
I am trying to make a gallery, with each thumnail image being the button to a separate slide with more info about the image. I got the links to work, but not the mouse over effect. I really don’t want to have to use the dotted green line, so any help would be greatly appreciated.