How to Batch Insert Multiple Pictures to Your Word Document

In this article, we would like to offer you the way to batch insert multiple pictures to your Word document.

You can feel comfortable while working with pictures in Word. Once you insert a picture into document, you may have to manually resize it or enter its name around. How about use a macro to automatically perform the task?Batch Insert Multiple Pictures to Your Word Document

The macro we are going to present you is capable of following functions:

  1. Firstly, it inserts exact number of pictures you specify in each page.
  2. Secondly, it inserts the name below each picture.
  3. Thirdly, it resizes pictures according to the size numbers you enter.

Now let’s look at how we get it to work.

Batch Insert Multiple Pictures to Document

  1. First of all, arrange all pictures to be inserted under the same folder.
  2. Then press “Alt+ F11” to invoke VBA editor in Word.
  3. Next click “Normal” project.
  4. Then on the menu bar, click “Insert”.
  5. And on the drop-down menu, choose “Module”.Click "Normal"->Click "Insert"->Click "Module"
  6. Open the module by double click and paste following codes:
Sub InsertSpecificNumberOfPictureForEachPage()
  Dim StrFolder As String
  Dim strFile As String
  Dim objDoc As Document
  Dim dlgFile As FileDialog
  Dim objInlineShape As InlineShape
  Dim nResponse As Integer
  Dim strPictureNumber As Integer
  Dim strPictureSize As String
  Dim n As Integer  

  Set dlgFile = Application.FileDialog(msoFileDialogFolderPicker)
  
  With dlgFile
    If .Show = -1 Then
      StrFolder = .SelectedItems(1) & "\"
    Else
      MsgBox ("No Folder is selected!")
      Exit Sub
    End If
  End With

  strFile = Dir(StrFolder & "*.*", vbNormal)
  strPictureNumber = InputBox("Input the number of the picture for each page", "Picture Number", "For exemple: 1")
  n = 1  

  While strFile <> ""
    Selection.InlineShapes.AddPicture FileName:=StrFolder & strFile, LinkToFile:=False, SaveWithDocument:=True
    Selection.TypeParagraph
    Selection.Collapse Direction:=wdCollapsEnd
    Selection.TypeText Text:=Left(strFile, InStrRev(strFile, ".") - 1)
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    If ActiveDocument.InlineShapes.Count = strPictureNumber * n Then
      Selection.InsertNewPage
      Selection.TypeBackspace
      n = n + 1
    End If
    Selection.TypeParagraph
    strFile = Dir()
  Wend

  For Each objInlineShape In ActiveDocument.InlineShapes
    objInlineShape.Select
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
  Next objInlineShape

  nResponse = MsgBox("Do you want to resize all pictures?", 4, "Resize Picture")
  If nResponse = 6 Then
    strPictureSize = InputBox("Input the height and width of the picture, seperated by comma", "Height and Width", "For exemple:500,500")
    For Each objInlineShape In ActiveDocument.InlineShapes
      objInlineShape.Height = Split(strPictureSize, ",")(0)
      objInlineShape.Width = Split(strPictureSize, ",")(1)
    Next objInlineShape
  End If
End Sub
  1. Then click “Run” or hit “F5”.Paste Codes->Click "Run"
  2. While running the macro, “Browse” window will pop up. Just pick the folder you keep pictures in step 1 and click “OK”.Pick a Folder->Click "OK"
  3. Next in “Picture Number” box, enter a number representing the total number of pictures you want in a single page. And click “OK” to proceed.Enter a Number ->Click "OK"
  4. In “Resize Picture” box, click “Yes” to resize all pictures and “No” to cancel it.Click "Yes" Or "No" in "Resize Picture" Box
  5. Now in “Height and Width” box, enter values and use comma to separate. Remember to enter height first and then the width. There is no space after comma.
  6. Similarly, click “OK” to move on.Enter Height and Width Values and Use Comma to Separate->Click "OK"

Now there are 2 pictures in one page and each has its name below it. Here is the outcome:Resized Pictures

Keep an Eye on Data Integrity

There is always the risk to losing data or have it compromised somehow. This means we have to check data integrity regularly. And once we find any sign of Word damage, the best way to recover data is to get a repairing tool.

Author Introduction:

Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including Excel recovery and pdf repair software products. For more information visit www.datanumen.com