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

8 responses to “How to Batch Insert Multiple Pictures to Your Word Document”

  1. Разобрался сам, так как такой информации нигде не нашел, и решил поделиться со всеми.

    Если вам нужно просто засунуть много сканов документа в вордовский файл, чтобы все картинки были в одном файле нужно нажать “Вставить картинку” и в окне обзора файловой системы выбрать несколько сканов. Однако, автоматически эти сканы добавятся в хаотическом порядке. Чтобы они добавились в правильном порядке – нужно зажать клавишу CTRL и постепенно выделять файлы в обратном порядке. После этого нажать “Добавить”.

    Есть еще 1 момент. Перед добавлением картинок нужно изменить размеры полей документа, если вы хотите, чтобы документ отображал все картинки в полном масштабе автоматически. Например я ставил 0,5см, можно попробовать и 0см для всех полей всех сторон.

    Надеюсь помог. Удачи.

  2. THANK YOU! This module code saved me so much work! I appreciate you and all who are willing to share your knowledge with others.

  3. What unit of measurement for the height & width?….millimeters? Inches? Pixels?

    Also, if I need to insert 1 photo per page and I have 100 photos, I need 100 pages. Will this macro (or Word) automatically replicate the first page 99 times, allowing 1 photo per page to be inserted, or must I create a 100 page Word doc template for this to work? If so, how do I create the 100 page master (empty) word doc…there seems to be no way in Word. Thanks

  4. Can you please add a scenario in the code where the word will be saved inside the selected folder with the same name of the said folder? Example folder name: TEST1234; Word filename: TEST1234.docx. The word should be saved inside the folder.

  5. unifiram (developmental code name dm-235) is an experimental drug which has antiamnesic effects in animal studies and with significantly higher potency than piracetam. sunifiram is a molecular simplification of unifiram (dm-232). another analogue is sapunifiram (mn-19). as of 2016, sunifiram had not been subjected to toxicology testing, nor to any human clinical trials, and is not approved for use anywhere in the world.

  6. Thank you for this macro. Do you have a macro that inserts any number of selected pictures into either 3 or 6 pictures per A4 page into the second column of a 3-column table?
    Column widths: Col1 = 1cm; Col2 = 8cm; Col3 = 8cm

Leave a Reply

Your email address will not be published. Required fields are marked *