Incorrect operation of the Visual Basic script in the PowerPoint slides

Nick Green 40 Reputation points
2024-07-18T19:48:50.08+00:00

Hello community. I need your help.

In my work I need to export shapes from PowerPoint slides. Since it is boring to do it manually (by selecting the "save as image" option) I use the MVB script (found here in another thread).

Sub ExportShapesAsPNGs()
	Dim sld As Slide
	Dim shp As Shape
	Dim path As String
	Dim name As String
	Dim i As Integer

	path = "

	For Each sld In ActivePresentation.Slides
		For Each shp In sld.Shapes
			If shp.Type <> msoPlaceholder Then
				i = i + 1
				name = sld.name & "_" & i & ".png"
				shp.Export path & name, ppShapeFormatPNG
			End If
		Next shp
	Next sld
	MsgBox i & " shapes exported as PNGs."
End Sub

It worked perfectly. Until I came across a slide from which it flatly refused to export a specific shape. It exports all shapes except one. This top shape with the text "Test" in yellow. The bottom shape "Test2" is exported as png without problems. Both shapes are exported without problems when choosing the "save as image" option. What is not working as expected in this script?

Untitled

Link to the tested slide on Dropbox: https://www.dropbox.com/scl/fi/ifv278qx0ng4zg1nebzn2/Test.pptx?rlkey=0o2mjyhgf72tsugrfv45m7zm1&st=zqok53e9&dl=0

PowerPoint
PowerPoint
A family of Microsoft presentation graphics products that offer tools for creating presentations and adding graphic effects like multimedia objects and special effects with text.
301 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,963 questions
PowerPoint Management
PowerPoint Management
PowerPoint: A family of Microsoft presentation graphics products that offer tools for creating presentations and adding graphic effects like multimedia objects and special effects with text.Management: The act or process of organizing, handling, directing or controlling something.
230 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 54,646 Reputation points
    2024-07-18T20:45:20.9533333+00:00

    The reason it is failing for your specific sample is that the first shape is a placeholder. In your macro it checks to see if the shape is a placeholder and skips over it if it is. I don't know why the macro was written this way. Irrelevant if you replace it with another shape then it works.

    3 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.