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.
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