Save images of PowerPoint slides using VBA

step3_16x9

Macros are useful for speeding up processes that can be otherwise cumbersome to perform. Here, we’ll create a macro to save the slides in a PowerPoint presentation as images.

As we do this, we’ll improve on the basic PowerPoint process and specify the image type and size in the macro.

As you can save slides in PowerPoint as JPG, PNG or BMP format images, our macro will contain a variable to control the file format to use. It will also allow you to save the images at your choice of width and height.

Just be aware that these values must be in the same ratio as the slide size. So for a 4:3 scale presentation, the ratio between the width and height should also be 4:3 or the image proportions will be distorted.

To create the macro, open your PowerPoint presentation, select the Developer tab and click Visual Basic.

Inside the VBA Editor, choose ‘Insert > Module’ and type this code:

Sub SaveSlidesAsImage()
Dim sldPath As String
Dim sldImageName As String
Dim sldImageType As String
Dim sldSlide As Slide
Dim sldImageWidth As Long
Dim sldImageHeight As Long
Dim slideNo As Integer

slideNo = 1
sldImageWidth = 1920
sldImageHeight = 1080
sldImageType = “jpg” ‘ use png, jpg, or bmp
sldPath = ActivePresentation.Path
userMessage = “Slide images will be saved to the current path: “ & vbNewLine & sldPath
userMessage = userMessage & vbNewLine & “Any existing files will be overwritten without warning”
userMessage = userMessage & vbNewLine & “click Ok to continue, or Cancel to abort save.”

On Error GoTo Err_Caught

If Len(sldPath) > 0 Then
response = MsgBox(userMessage, vbOKCancel, “Check Path”)
If response = vbOK Then
For Each sldSlide In ActivePresentation.Slides
sldImageName = “\slide” & slideNo & “.” & sldImageType
sldSlide.Export sldPath & sldImageName, sldImageType, sldImageWidth, sldImageHeight
slideNo = slideNo + 1
Next sldSlide
Else
MsgBox “Save Aborted”
Exit Sub
End If
Else
MsgBox “File not saved, please save the PowerPoint file before running this macro.”
Exit Sub
End If

Err_Caught:
If Err <> 0 Then
MsgBox “Error encountered, Program aborted”
End If
End Sub

Save the PowerPoint file as a PPTM Macro Enabled file and test the macro.

The macro export process does not check to see if the images already exist so any existing images in the folder will be overwritten without warning.

step1Step 1

Create the macro in a new module inside the PowerPoint presentation file.

Macros in PowerPoint are limited to use with the current file only.

Step 2

step2Save the file as a .pptm macro-enabled file before testing it.

For future use, you can save it as a potm macro-enabled template file but you’ll need to test the macro using the pptm file as its location is where the images will be saved.

Step 3

When you run the macro, all the slides in the presentation are saved as images in the same location as the presentation itself.