How to Set a Selected Picture as a Slide Background Using PowerPoint VBA
Question details
The user wants to use a VBA macro in PowerPoint to take the currently selected picture on a slide and set it as the background for that specific slide.

- Product
- PowerPoint
- Device & OS
- not provided
- Scenario
- Automating presentation formatting with VBA macros to dynamically change slide backgrounds based on inserted pictures.
- Observed behavior
- A macro is required to extract a selected shape (picture) and apply it as the slide's background fill because PowerPoint VBA cannot directly assign a shape object as a background without exporting it first.
Ensure that you have enabled the Developer tab in PowerPoint to access the VBA editor, and remember to save your presentation as a Macro-Enabled Presentation (.pptm) before running the code.
Export the Picture and Apply Using UserPicture Method
Because VBA requires an actual image file to load a background, the solution involves exporting the selected picture to your hard drive, deleting the original shape, and then setting the exported image as the slide background.
VBA cannot directly assign a shape object currently on the slide to the background. You must first save the shape as an external image file (like PNG or JPG) and then instruct PowerPoint to load that file as the background fill.
Click on the picture on your slide that you want to set as the new background.
Press Alt + F11 to open the VBA Editor, insert a new module, and define a sub-procedure for your macro.
Write code to export the selected shape to a temporary path on your computer using the Shape.Export method (e.g., ActiveWindow.Selection.ShapeRange(1).Export).
Remove the original shape from the slide using the Shape.Delete method so it does not overlap with the new background.
Set Slide.FollowMasterBackground = False to ensure the new background overrides the default master slide design.
Apply the exported image to the slide background using the Slide.Background.Fill.UserPicture method, providing the exact file path of your exported image.

Automate Slide Backgrounds Easily with WPS Presentation
WPS Office comes with robust macro support allowing you to automate repetitive tasks like setting slide backgrounds. You can write and run macros seamlessly, enjoying high compatibility with Microsoft PowerPoint files.
- 1. Open WPS Presentation: Launch WPS Presentation and open your slideshow.
- 2. Access Developer Tools: Go to the Developer tab and click on 'Macros' or 'Visual Basic' to open the code editor.
- 3. Insert the VBA Code: Insert a new module and paste your VBA script for exporting and applying the slide background.
- 4. Select and Run: Select the desired image on your slide, then run the macro to instantly update the background.

Frequently Asked Questions
Why can't I directly assign a shape to the slide background in VBA?
PowerPoint VBA does not have a direct method to set an in-slide shape object as a background fill. The Background.Fill.UserPicture method strictly requires a valid file path pointing to an external image file.
How do I ensure the new background doesn't affect all slides?
By applying the background specifically to the ActiveWindow.View.Slide object and setting its FollowMasterBackground property to False, the macro ensures only the current slide is modified without altering the slide master.
What format is best for exporting the picture in VBA?
It is recommended to export the picture as a PNG or JPG file. Use the ppShapeFormatPNG enumeration if the image contains transparency, while ppShapeFormatJPG is suitable for standard photographs to keep the file size manageable.




