You are on page 1of 2

Sub InsertSpecificNumberOfPictureForEachPage()

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

You might also like