|
word宏,请参考,图片1.png可预先处理一下。。。
Option Explicit
Option Compare Text
Sub test()
Dim br$(), i&, r&, n&, iPosRow&, iPosCol&, wdApp As Word.Application
Dim strFileName$, strPath$, strPicPath$, strPicName$, pic As InlineShape
strPath = ThisDocument.Path & "\"
strPicPath = strPath & "归档\"
strFileName = Dir(strPicPath & "*.jpg")
Do Until strFileName = ""
r = r + 1
ReDim Preserve br(1 To r)
br(r) = strPicPath & strFileName
strFileName = Dir
Loop
If r = 0 Then Exit Sub
Application.ScreenUpdating = False
n = -Int(-UBound(br) / 4)
With Documents.Add
With .PageSetup
.LeftMargin = .LeftMargin - 20
.RightMargin = .RightMargin - 20
End With
strPicName = strPath & "图片1.png"
With .Tables.Add(Range:=Selection.Range, NumRows:=n, NumColumns:=4, DefaultTableBehavior:=8)
.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter
With .Borders
.InsideLineStyle = wdLineStyleNone
.OutsideLineStyle = wdLineStyleNone
End With
For i = 1 To UBound(br)
iPosRow = -Int(-i / 4): iPosCol = IIf(i Mod 4 = 0, 4, i Mod 4)
Set pic = .Cell(iPosRow, iPosCol).Range.InlineShapes.AddPicture(strPicName)
With pic
.LockAspectRatio = True
.Height = 65
End With
Set pic = .Cell(iPosRow, iPosCol).Range.InlineShapes.AddPicture(br(i))
With pic
.LockAspectRatio = True
.Height = 65
End With
Next i
End With
.SaveAs2 strPath & "结果": .Close
End With
Application.ScreenUpdating = True
Beep
End Sub
|
|