Use Word VBA to Insert a Selected Picture into a Shape
Question details
The user needs a Word VBA macro that prompts for an image and uses it as the fill of a specific shape.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A macro should let the user choose an image file instead of relying on a fixed filename.
- Observed behavior
- A previous attempt either raised an error when referencing the shape or inserted a small picture elsewhere in the document.
In Word, open Home > Select > Selection Pane and check the target shape's exact name, including spaces and numbering. Save the document as a macro-enabled Word document (.docm) if you want to retain the macro.
Fill the named Word shape with a picture selected through VBA
Use this macro to choose an image and apply it to an existing shape instead of inserting a separate picture.
Open Home > Select > Selection Pane and note the exact name of the shape in the document body. For example, "Rectangle 21" is different from "Rectangle21".
Open the VBA editor from Developer > Visual Basic, choose Insert > Module, and paste this code: Sub FillShapeWithSelectedPicture() Dim picker As FileDialog Dim picturePath As String Set picker = Application.FileDialog(3) With picker .Title = "Select a picture" .AllowMultiSelect = False .Filters.Clear .Filters.Add "Pictures", "*.jpg; *.jpeg; *.png; *.gif; *.bmp" If .Show <> -1 Then Exit Sub picturePath = .SelectedItems(1) End With ActiveDocument.Shapes("Rectangle 21").Fill.UserPicture picturePath End Sub
In the last line of the macro, replace "Rectangle 21" with the exact name shown in the Selection Pane. Keep the quotation marks around the name.
In Word, open Developer > Macros, select FillShapeWithSelectedPicture, and click Run. Choose an image in the file picker and confirm the selection; canceling the picker exits the macro without changing the shape.

Edit Word documents with WPS Office
WPS Office is a free, lightweight alternative for working with Word documents in a familiar interface. Its Word format support helps you move documents between suites, although it does not fix Microsoft Word VBA errors.

Frequently Asked Questions
Why does the shape reference produce an error?
Check the name in Home > Select > Selection Pane and use it exactly in Shapes("name"). Spaces and numbering matter. Also check whether the shape is in a header or footer rather than the document body.
How does the macro put the picture inside the shape?
The macro passes the selected file path to the named shape's Fill.UserPicture method. This applies the picture as the shape's fill instead of adding a separate picture elsewhere.
What happens if I cancel the file picker?
The macro checks the result of the file picker's Show method and exits when you cancel, so it does not try to use a missing selected file.
Why does the file picker open in the Documents folder?
The picker opens in a default location determined by Office or the system. You can browse to another folder in the picker; the selected file's full path is then passed to UserPicture.
How do I keep the macro in my Word document?
Use File > Save As and choose Word Macro-Enabled Document (.docm). Macro security settings may require you to enable trusted macros before running it.




