Inserting an Image On a Specific Page

by Allen Wyatt
(last updated June 21, 2014)


Suman needs to use a macro to insert an image on page 10 of a particular document. He wonders about the best way, within the macro, to go about this.

If you want the image to be the only thing on page 10, then the task is rather easy: Use the macro to locate page 10, insert the image, and then insert a page break after the image. This then bumps everything after the image up by a page, such that the old page 10 becomes page 11, page 11 becomes page 12, and so on.

Sub InsertImage1()
    Dim PicPath As String

    PicPath = "C:\My Pictures\My Scans\scan0002.jpg"
    ActiveDocument.GoTo(What:=wdGoToPage, Count:=10).Select
    Selection.InlineShapes.AddPicture FileName:=PicPath, _
      LinkToFile:=False, SaveWithDocument:=True
    Selection.InsertBreak Type:=wdPageBreak
End Sub

The macro inserts the image as an inline shape. If you prefer, you could insert the image as a floating shape, which would allow text to wrap around the image. The following macro does that, as well as centering the image in the center of the page:

Sub InsertImage2()
    Dim PicPath As String
    Dim aShape As Shape

    PicPath = "C:\My Pictures\My Scans\scan0002.jpg"
    ActiveDocument.GoTo(What:=wdGoToPage, Count:=10).Select
    Set aShape = Selection.InlineShapes.AddPicture(FileName:=PicPath, _
      LinkToFile:=False, SaveWithDocument:=True).ConvertToShape
    With aShape
        .WrapFormat.Type = wdWrapTight
        .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
        .RelativeVerticalPosition = wdRelativeVerticalPositionPage
        .Top = wdShapeCenter
        .Left = wdShapeCenter
    End With
End Sub

If you wanted your image to replace an existing image (perhaps with an updated image), then the easiest way is to simply use a bookmark to "mark" the existing image. (You'll need, in other words, to bookmark the current image on page 10. It is possible, of course, that the bookmark could "float" to a different page as you add or remove information from the document.) The following macro will locate the bookmark (named Bk1) and replace it with an inline shape.

Sub InsertImage3()
    Dim PicPath As String
    Dim BmkName As String

    PicPath = "C:\My Pictures\My Scans\scan0002.jpg"
    BmkName = "Bk1"

    With ActiveDocument
        If .Bookmarks.Exists(BmkName) Then
            Dim WrdPic As Word.InlineShape
            Set WrdPic = .Bookmarks(BmkName).Range _
              .InlineShapes.AddPicture(PicPath, False, True)
        End If
    End With
End Sub

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13139) applies to Microsoft Word 2007, 2010, and 2013.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...


Passing Parameters to Functions

Functions can be used to perform repetitive tasks and return values to your main program. You can also pass values to a ...

Discover More

Clearing the Undo Stack in a Macro

Excel keeps track of the actions you take so that you can undo those actions if any are taken in error. You may want to ...

Discover More

Extracting E-mail Addresses from Hyperlinks

If you have a list of hyperlinked e-mail addresses in a worksheet, you may want to extract the addresses from those ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (ribbon)

Writing On Top of Locked Graphics

Getting graphics to appear right where you want them in relation to the text in your document can be a challenge. One ...

Discover More

Resize Graphics Outside of Word

Need your graphics to be larger or smaller than they first appear when you insert them in a document? Your best bet may ...

Discover More

Editing Wrap Points

If you have a graphic that has text wrapping around it, you might want a way to modify the wrapping path used by Word. ...

Discover More

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 5 + 9?

2018-03-02 16:23:12



I have a vertical line that I added to a Word document, but the line moves when I add a table next. How do I keep the line fixed to the page? There is an option to do it in the drop down for drawing tools/format/warp text/Fix Position on Page. How do I do it programmatically?

2014-08-21 01:45:44


Hi Ken Endacott,

It's very nice of you to have shared your tip for the benefit of others. Thanks. That you've also considered all possibilities during execution is praiseworthy indeed!

Sorry for the delayed appreciation! I happened to see your tip only today (21st Aug 2014).

2014-07-05 08:21:22

Ken Endacott

Rather than bookmark a picture so that it can be replaced, a better method would be to simply replace whatever picture is on the page. The following macro will select the contents of page 10 and if it has one or more inline pictures replace the first picture with the new picture. Additional statements could be added to set the new picture to the same size as the old picture.

Sub ReplacePicture()
Dim r1 As Range
Dim r2 As Range
Dim nPages As Long
Dim nP As Long
Dim PicPath As String

PicPath = "C:My PicturesMy Scansscan0002.jpg"
nP = 10

nPages = ActiveDocument.ComputeStatistics(statistic:=wdStatisticPages)
If nP > nPages Then
MsgBox "You are trying to go to a non existent page"
Exit Sub
End If
Set r1 = ActiveDocument.GoTo(What:=wdGoToPage, Count:=nP)
If nP = nPages Then
Set r2 = ActiveDocument.Range
r1.End = r2.End
Set r2 = ActiveDocument.GoTo(What:=wdGoToPage, Count:=nP + 1)
r1.End = r2.Start - 2
End If
If r1.InlineShapes.Count = 0 Then
MsgBox "Page " & nP & " does not have an inline picture"
Selection.InlineShapes.AddPicture FileName:=PicPath, _
LinkToFile:=False, SaveWithDocument:=True
End If
End Sub

2014-06-26 01:04:25


Hi Allen,

Thanks you very much for your code, it really helpful.

This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Newest Tips

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.