Yesterday I posted an image of some PowerPoint VBA code on LinkedIn and Twitter and a lot of people have asked for a copy of the code.
So I have made a Power Point file with the code included and a small instruction on how to use it.
The code has been changed compared to the posted image as it ran to fast for Power Point β so I added a pause in the code to wait 1 second for each conversion.
The Code
Sub ConvertAllPBIToImages()
Dim x As Slide
Dim shp As Shape
Dim sShapes As Shapes
'Loop through all the slides
For Each x In ActivePresentation.Slides
x.Select
'Loop through all the shapes on the slide
For Each shp In x.Shapes
'Is it a Power BI App - Report
If shp.Title = "Microsoft Power BI" Then
'Inserted to make sure as the code sometimes runs
'a bit to fast for Power Point
WAIT = Timer
While Timer < WAIT + 2
DoEvents 'do nothing
Wend
shp.Copy
Set sShapes = x.Shapes
x.Shapes.PasteSpecial ppPasteBitmap
shp.Delete
End If
Next
Next
End Sub
Here is a link to a file with the code.
Hope you find it useful.
Thank you for sharing.
I’ve tried the macro again and again, but it seems not working. I had tried step by step, bit the shape (AddInn) object will be not selected. Are there some changes with current add inn versions?
Do you get an error message or ?
Hello Erik, no error message. Macro runs, goes from slide to slide, but shapes will not be activated and not transferred to image.
Hi
The code expects the shapes with the Power BI visual should have a title called Microsoft Power BI .
Apparently the Add-in has been updated so the title is empty – this means that the shape with Power BI visual isnt found and thereby no conversion takes place.
If you modify the name of the visual via the selection pane – to “Microsoft Power BI”
and change the code line
If shp.Title = “Microsoft Power BI” Then
to
If shp.Name = “Microsoft Power BI” Then
then it should do the trick
Erik
Perfect, thank you, that works!
Do you also have a trick, in case I only wants to freeze the data for all Power BI shapes (functionality βshow as Saved Imagesβ)?
I am not sure what you mean – doesn’t the macro do exactly that ?
Wonderful stuff – very much appreciated!
Hello Erik
This looks promising but it pastes the static image in the middle of the slide instead of where the PowerBi visual was. Is there anyway to get it to retain the location of the original visual?
Hello
You can modify the code so it reads the x and y location before the conversion to image and the use those on the image after its pasted