Skip to content

October 18, 2011


Insert Multiple image quickly into Microsoft Word 2007 and 2010 [UPDATED]

Ever wanted to quickly insert multiple images in to Microsoft Word? The following macro allows you to do this but as an added extra it will also add a caption underneath each image with the name of the file. Handy for all those images you need to include in your reports!

When in Word 203/2007, press alt-F11 and you will be greeted with the visual basic module. Copy and Paste the code in to the module window under the Normal document (this is your template document, this will allow you to use this code on all new documents).

Sub InsertImages()
Dim doc As Word.Document
Dim bkmName As String
Dim SigFile As String
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Set doc = ActiveDocument
Dim vrtSelectedItem As Variant
Dim theText() As String
Dim theText2 As String

With fd
.Filters.Add "Images", "*.gif; *.jpg; *.jpeg", 1

.FilterIndex = 1

If .Show = -1 Then

For Each vrtSelectedItem In .SelectedItems

Set mg2 = ActiveDocument.Range
mg2.Collapse wdCollapseEnd

doc.InlineShapes.AddPicture _
FileName:=vrtSelectedItem, _
LinkToFile:=False, SaveWithDocument:=True, Range:=mg2

Set mg1 = ActiveDocument.Range
mg1.Collapse wdCollapseEnd
mg1.MoveEnd Unit:=wdCharacter, Count:=0

theText() = Split(vrtSelectedItem, "\")
theText2 = theText(UBound(theText))
theText2 = Left(theText2, InStrRev(theText2, ".")-1)

mg1.Text = Chr(13) + Chr(10) + theText2 + Chr(13) + Chr(10) + Chr(13) + Chr(10)

Next vrtSelectedItem
End If
End With

Set fd = Nothing

End Sub

Read more from coding, Misc
11 Comments Post a comment
  1. Ian Smith
    Apr 8 2012

    Hi Steph,

    You’ve saved me a shed load of work with this macro. Cheers mate.

  2. Apr 8 2012

    No worries. I’m glad it was of use Ian

  3. Apr 20 2012

    macro works great!!! any chance you could also Figure them all as well so I could build a table of contents at the end?

  4. Kathleen
    Apr 27 2012

    What if you want to have a landscape orientation with 4 photos with captions per page (2 rows of 2 photos)? I’ve been trying a few different ways but can’t seem to get the photos to be 2 rows of 2 photos.


  5. Ken
    Oct 29 2012

    I am new at the visual basic and can’t figure out where to paste this into 2010 WORD. I don’t see a window or anywhere that will allow a paste function. This is exactly what I need to insert photos.


  6. Antonio Zighelboim
    Nov 30 2012

    Very nice! Thank you.
    However, for some reason, the las picture I pick ends up in the first place.
    Any ideas?

  7. A. Raab
    Dec 1 2012

    Genius !!!! thank you very very much !!!

  8. sandeep
    Feb 25 2013

    It is working perfectly fine… have saved my day.thanks for sharing this code.

  9. Antonio Zighelboim
    Feb 28 2013

    Sub InsertMultipleImages()
    Dim fd As FileDialog
    Dim oTable As Table
    Dim sNoDoc As String
    Dim vrtSelectedItem As Variant
    If Documents.Count = 0 Then
    sNoDoc = MsgBox(” ” & _
    “No document open!” & vbCr & vbCr & _
    “Do you wish to create a new document to hold the images?”, _
    vbYesNo, “Insert Images”)
    If sNoDoc = vbYes Then
    Exit Sub
    End If
    End If
    ‘add a 1 row 2 column table to take the images
    Set oTable = Selection.Tables.Add(Selection.Range, 1, 2)
    oTable.AutoFitBehavior (wdAutoFitFixed)
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
    .Title = “Select image files and click OK”
    .Filters.Add “Images”, “*.gif; *.jpg; *.jpeg; *.bmp; *.tif; *.png”
    .FilterIndex = 2
    If .Show = -1 Then
    oTable.Cell(1, 1).Select
    For Each vrtSelectedItem In .SelectedItems
    With Selection
    .InlineShapes.AddPicture FileName:= _
    vrtSelectedItem _
    , LinkToFile:=False, SaveWithDocument:=True, _
    .MoveRight Unit:=wdCell
    End With
    Next vrtSelectedItem
    End If
    End With
    If Len(oTable.Rows.Last.Cells(1).Range) = 2 Then
    End If
    Set fd = Nothing
    End Sub

  10. Irv
    May 10 2013

    To have the images appear in two columns on a landscape-oriented page, establish those page settings in Word before running the macro. Manipulating the page settings seems to be a good way to make the images appear as you want them. Evidently the default is for the images appear full size or, if wider than the page margins, to shrink to fill the available space. To make the images smaller on the page, without re-sizing them in another program, set the page margins to force the images into a smaller space. Thus if you want the images to be 4.5 inches wide on a portrait-oriented page, set the left and right margins at 2 inches each. You can re-set the margins to something wider after importing without causing the images to expand.

  11. David
    May 30 2013

    dragging multiple (numbered) images into word screwed up sequence. browsing for a solution came across your post. brilliant – what a time saver

Share your thoughts, post a comment.


Note: HTML is allowed. Your email address will never be published.

Subscribe to comments


This blog is monetized using Are-PayPal WP Plugin