当需要将数十张图片批量以表格形式插入word中,并需要在下面显示文件名时,本工具能够发挥这样的功能,按照您的需求自动进行调整,实现自动插入图片于表格中,并按比例调整大小。
当需要将数十张图片批量以表格形式插入word中,并需要在下面显示文件名时,本工具能够发挥这样的功能,按照您的需求自动进行调整,实现自动插入图片于表格中,并按比例调整大小。
Sub 每行插入表格n个图()
On Error Resume Next
Application.ScreenUpdating = False
Dim D As FileDialog, a, P As InlineShape, t As Table
If Selection.Information(wdWithInTable) = True Then MsgBox "请将光标置于表格之外!": Exit Sub
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "请选择..."
If .Show = -1 Then
n = InputBox("请输入表格的列数:", "列数", 3)
M = .SelectedItems.Count
Debug.Print "共有" & M & "个图片"; M
h = IIf(M / n = Int(M / n), 2 * M / n, 2 * (Int(M / n) + 1))
Set t = ActiveDocument.Tables.Add(Selection.Range, h, n)
t.Borders.Enable = True
t.Borders.OutsideLineStyle = wdLineStyleDouble
For Each a In .SelectedItems
B = Split(a, "\")(UBound(Split(a, "\")))
C = Split(B, ".")(0)
Set P = Selection.InlineShapes.AddPicture(FileName:=a, SaveWithDocument:=True)
With P
w = .Width
.Width = Int(410 / n)
.Height = .Width * .Height / w
End With
i = i + 1
Selection.MoveLeft wdCharacter, 1
Selection.MoveDown wdLine, 1
Selection.TypeText C
Selection.Cells(1).Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter '决定了首行居中
Selection.HomeKey
Selection.MoveDown wdLine, -1
Selection.MoveRight wdCharacter, 2
Debug.Print i, n
If i = Val(n) Then
Selection.MoveRight wdCharacter, 1
Selection.Cells(1).Select
Selection.EndKey
Selection.MoveDown wdLine, 1
i = 0
End If
Next
End If
End With
Application.ScreenUpdating = True
End Sub
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
![[VBA][办公]以表格形式在word中插入多个图片](https://www.autoahk.com/wp-content/uploads/2017/12/360截图20171228221319023.jpg)

