Document Editing Problems

Insert a Picture into a Word Text Box Bookmark with VBA

Chanuka GeekiyanageChanuka Geekiyanage Nov 27, 2026 868 views

Question details

Insert a picture at a bookmark inside a Word text box using VBA.

Insert a Picture into a Word Text Box Bookmark with VBA
Product
Microsoft Word
Device & OS
not provided
Scenario
A VBA macro needs to place an image at a named bookmark inside a text box.
Observed behavior
Inserting the picture can fail when the macro navigates to the bookmark through Selection instead of using its Range.
Before you start

Confirm that the document contains a named bookmark inside the text box and that the image file is accessible. Open the document in a desktop version of Word that supports VBA, and enable macros only if you trust the code.

Solution 1Recommended

Insert the picture using the bookmark's Range

Use this method to insert an inline image without moving Selection into the text box, then restore the bookmark around the image.

The macro inserts the image into the bookmark's Range. If the bookmark spans existing text, that text is replaced; use an empty bookmark if you do not want to replace text.

After insertion, the macro uses the picture's Range to recreate the bookmark because inserting content can remove it.

1
Open the VBA editor

In Word, open the Developer tab and select Visual Basic. In the VBA editor, select Insert > Module.

2
Add the macro

Paste this code into the module, then replace the sample bookmark name and image path with your own: Sub InsertPictureAtBookmark() Const bookmarkName As String = "PictureBookmark" Const imagePath As String = "C:\Images\picture.jpg" Dim doc As Document Dim targetRange As Range Dim picture As InlineShape Dim pictureRange As Range Set doc = ActiveDocument If Not doc.Bookmarks.Exists(bookmarkName) Then MsgBox "Bookmark not found: " & bookmarkName Exit Sub End If If Not FileExists(imagePath) Then MsgBox "Image file not found: " & imagePath Exit Sub End If Set targetRange = doc.Bookmarks(bookmarkName).Range Set picture = doc.InlineShapes.AddPicture( _ FileName:=imagePath, LinkToFile:=False, _ SaveWithDocument:=True, Range:=targetRange) Set pictureRange = picture.Range.Duplicate If doc.Bookmarks.Exists(bookmarkName) Then doc.Bookmarks(bookmarkName).Delete End If doc.Bookmarks.Add Name:=bookmarkName, Range:=pictureRange End Sub Function FileExists(filePath As String) As Boolean On Error Resume Next FileExists = (Len(Dir$(filePath)) > 0) On Error GoTo 0 End Function

3
Run and check the macro

With the intended document active, select Developer > Macros, choose InsertPictureAtBookmark, and select Run. Check the text box to confirm the picture appears.

Insert the picture using the bookmark's Range
Bookmark after insertion: The recreated bookmark surrounds the inserted picture. Running the macro again replaces the bookmarked picture with the specified image.
Free Microsoft Office alternative

Edit Word documents and pictures with WPS Writer

WPS Office is a free, lightweight alternative with a familiar interface for editing documents and inserting pictures. Its Word format compatibility makes it easy to move existing documents into WPS Writer, although it does not fix Microsoft Word's VBA behavior.

Insert and format pictures in WPS Writer documents.Open and edit Microsoft Word DOC and DOCX files.Use a familiar interface for everyday document editing.Work with a free, lightweight office suite.
microsoft office alternative - wps office

Frequently Asked Questions

Why should I use the bookmark's Range instead of Selection?

A bookmark inside a text box may not work as expected when a macro navigates to it through Selection. Retrieving ActiveDocument.Bookmarks(bookmarkName).Range lets AddPicture target the bookmark directly.

Why does the macro recreate the bookmark?

Inserting content can remove a Word bookmark. The macro gets the inserted picture's Range and uses Bookmarks.Add to restore the bookmark around it.

What should I check if the picture is not inserted?

Check the bookmark name under Insert > Bookmark and confirm that the imagePath in the VBA module points to an existing, accessible image file. Also make sure the intended document is active before running the macro.

Will the macro replace text inside the bookmark?

Yes. If the bookmark's Range spans existing text, AddPicture replaces that text. Create an empty bookmark at the insertion point if you want to keep the surrounding text.