Add Picture Filenames as PowerPoint Slide Titles with VBA
Question details
Import pictures onto individual PowerPoint slides and use each filename, without its path or extension, as the slide title.

- Product
- Microsoft PowerPoint
- Device & OS
- not provided
- Scenario
- A user wants to create slides from a folder of pictures without manually adding a title to each slide.
- Observed behavior
- Each picture appears on its own slide with its filename displayed as a formatted title.
Place the pictures you want to import in one folder and open the destination presentation in desktop PowerPoint. The example below is for Windows and imports JPG, JPEG, and PNG files.
Import pictures and set slide titles with a PowerPoint VBA macro
Use this macro to add one slide per picture and format each filename as a white, centered title.
The macro adds slides to the end of the active presentation using the Title Only layout. It fits each picture within the slide, removes the final filename extension, and brings the title placeholder in front of the picture.
In desktop PowerPoint on Windows, open the presentation and press Alt+F11. In the VBA editor, select Insert > Module.
Paste this code into the module: Sub ImportPicturesWithTitles() Dim folderPath As String, fileName As String Dim ext As String, titleText As String Dim dotPos As Long Dim slideWidth As Single, slideHeight As Single Dim sld As Slide, pic As Shape, titleBox As Shape With Application.FileDialog(msoFileDialogFolderPicker) .Title = "Select the picture folder" If .Show <> -1 Then Exit Sub folderPath = .SelectedItems(1) & "\" End With slideWidth = ActivePresentation.PageSetup.SlideWidth slideHeight = ActivePresentation.PageSetup.SlideHeight fileName = Dir(folderPath & "*.*") Do While fileName <> "" dotPos = InStrRev(fileName, ".") If dotPos > 0 Then ext = LCase$(Mid$(fileName, dotPos + 1)) If ext = "jpg" Or ext = "jpeg" Or ext = "png" Then titleText = Left$(fileName, dotPos - 1) Set sld = ActivePresentation.Slides.Add( _ ActivePresentation.Slides.Count + 1, ppLayoutTitleOnly) Set pic = sld.Shapes.AddPicture(folderPath & fileName, _ msoFalse, msoTrue, 0, 0, -1, -1) pic.LockAspectRatio = msoTrue pic.Width = slideWidth If pic.Height > slideHeight Then pic.Height = slideHeight pic.Left = (slideWidth - pic.Width) / 2 pic.Top = (slideHeight - pic.Height) / 2 Set titleBox = sld.Shapes.Title With titleBox.TextFrame.TextRange .Text = titleText .Font.Size = 25 .Font.Color.RGB = RGB(255, 255, 255) .ParagraphFormat.Alignment = ppAlignCenter End With titleBox.ZOrder msoBringToFront End If End If fileName = Dir() Loop End Sub
Place the cursor inside ImportPicturesWithTitles and press F5. In the folder picker, select the picture folder and confirm your choice.
Return to PowerPoint and check the new slides and title visibility. To keep the macro, select File > Save As and choose PowerPoint Macro-Enabled Presentation (.pptm).

Create picture slides in WPS Presentation
WPS Office is a free, lightweight alternative with a familiar interface for working on presentations. Open compatible PowerPoint files in WPS Presentation and add pictures and titles manually; the PowerPoint-specific VBA macro is not guaranteed to run in WPS.

Frequently Asked Questions
Does the macro include the folder path in the slide title?
No. It uses the filename returned from the selected folder and removes the final extension, so a file named holiday.jpg becomes the title holiday.
Which picture formats does the macro import?
The example imports JPG, JPEG, and PNG files. The extension check uses lowercase comparisons, so uppercase extensions such as JPG are also accepted.
Why is the title hidden behind the picture?
The macro uses titleBox.ZOrder msoBringToFront to place the title above the picture. If a title is still hard to see, check whether its white text blends into a light part of the image.
Can I keep the macro in a regular PPTX file?
To retain VBA code, use File > Save As and select PowerPoint Macro-Enabled Presentation (.pptm). A PPTX file cannot retain the macro.
Can I run this macro in PowerPoint for the web?
No. Open the presentation in desktop PowerPoint to use the VBA editor and run the macro.




