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?
The macro we are going to present you is capable of following functions:
- Firstly, it inserts exact number of pictures you specify in each page.
- Secondly, it inserts the name below each picture.
- 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
- First of all, arrange all pictures to be inserted under the same folder.
- Then press “Alt+ F11” to invoke VBA editor in Word.
- Next click “Normal” project.
- Then on the menu bar, click “Insert”.
- And on the drop-down menu, choose “Module”.
- 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
- Then click “Run” or hit “F5”.
- While running the macro, “Browse” window will pop up. Just pick the folder you keep pictures in step 1 and click “OK”.
- 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.
- In “Resize Picture” box, click “Yes” to resize all pictures and “No” to cancel it.
- 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.
- Similarly, click “OK” to move on.
Now there are 2 pictures in one page and each has its name below it. Here is the outcome:
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.
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
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
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.
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.
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