Normally, you can insert multiple images into a Word document with their original sizes. However, sometimes you may need to arrange these images to have the same size upon insertion. This article will discuss how to insert multiple images with the same size in a Word document.
Insert Multiple Images with the Same Size Using VBA Code
The following VBA code can help you insert multiple images and resize them to a specified size simultaneously. Follow these steps:
- Press
ALT + F11
to open the Microsoft Visual Basic for Application window. - Click
Insert > Module
and paste the code below into the Module window.
Dim xDlg As FileDialog
Dim xFilePath As String
Dim xFileName As String
Dim xMsbBoxRtn As Long
Dim xPicSize As String
Dim xShape As InlineShape
Set xDlg = Application.FileDialog(msoFileDialogFolderPicker)
If xDlg.Show = -1 Then
xFilePath = xDlg.SelectedItems(1) & “\”
Else
Exit Sub
End If
xFileName = Dir(xFilePath & “*.*”, vbNormal)
While xFileName <> “”
If Not (Right(xFileName, 4) = “.png” Or Right(xFileName, 4) = “.bmp” _
Or Right(xFileName, 4) = “.jpg” Or Right(xFileName, 4) = “.ico”) Then
GoTo LblCtn
End If
With Selection
.InlineShapes.AddPicture xFilePath & xFileName, False, True
.TypeParagraph
.Collapse wdCollapsEnd
.TypeText Left(xFileName, InStrRev(xFileName, “.”) – 1)
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.TypeParagraph
End With
LblCtn:
xFileName = Dir()
Wend
ActiveDocument.InlineShapes(1).Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
xMsbBoxRtn = MsgBox(“Do you want to resize all pictures?”, vbYesNo, “Kutools for Word”)
If xMsbBoxRtn = 6 Then
xPicSize = InputBox(“Input the height and width of the picture, separated by comma”, “Kutools for Word”, “”)
End If
For Each xShape In ActiveDocument.InlineShapes
xShape.Height = Split(xPicSize, “,”)(0)
xShape.Width = Split(xPicSize, “,”)(1)
Next xShape
End Sub
- Press
F5
to run the code. A Browse window will appear; select the folder containing the images you want to insert. - Click
OK
, and a prompt will appear asking if you want to resize all pictures. - Click
Yes
and enter the height and width of the pictures separated by a comma in the text box. -
Click
OK
, and all the inserted images will be resized to the specified dimensions.
Note: The unit of measurement is points in the VBA code.
Now you have successfully inserted multiple images with the same size into your Word document.