|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub zldccmx()
- Application.ScreenUpdating = False
- Dim Nd As Document, Tb As Table
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set f = fso.GetFolder(ThisDocument.Path)
- pt = ThisDocument.Path & ""
- arr = Array("身份证,2_2", "驾驶证,2_2", "行驶证,4_2", "上岗证,1_2", "验收合格证,1_2", "强制险,1_1", "商业险,1_1", "验收表,1_1", "安全协议书,1_1")
- brr = Array("1-1.jpg", "1-2.jpg", "2-1.jpg", "2-2.jpg", "3-1.jpg", "3-2.jpg", "3-3.jpg", "3-4.jpg", "4.jpg", "5.jpg", "6.jpg", "7.jpg", "8.jpg", "9.jpg")
- For Each E In f.SubFolders
- p = 0
- Set Nd = Documents.Open(pt & "封面模板.docx")
- With ActiveWindow.Selection
- .EndKey Unit:=6
- .InsertBreak Type:=2 '' 分节
- .EndKey Unit:=6 '回到文档末尾
- For I = 0 To UBound(arr)
- ww = Split(arr(I), ",")
- .Style = ActiveDocument.Styles("正文")
- .Font.Size = 24
- .Font.Name = "黑体"
- .TypeText ww(0) '"身份证"
- .TypeParagraph
- .Style = ActiveDocument.Styles("正文")
- .Font.Size = 14
- tpsl = Split(ww(1), "_")
- cc = tpsl(1) '尺寸
- tpsl = tpsl(0) '数量
- If cc = 1 Then
- If tpsl = 1 Then
- rn = 1: cn = 1: rh = 22.5
- Else
- rn = 1: cn = 1: rh = 15
- End If
- Else
- Select Case tpsl
- Case 4
- rn = 2: cn = 2: rh = 5.2: cw = 7.5
- Case 2
- rn = 1: cn = 2: rh = 5.2: cw = 7.5
- Case 1
- rn = 1: cn = 1: rh = 11: cw = 15
- End Select
- End If
- Set Tb = ActiveDocument.Tables.Add(Range:=Selection.Range, NumRows:=rn, NumColumns:=cn, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed)
- With Tb
- .AutoFitBehavior wdAutoFitWindow
- .Style = "网格型"
- For j = 1 To 6
- .Borders(j).LineStyle = wdLineStyleNone
- Next
- .Borders.Shadow = False
- .Rows.WrapAroundText = True
- .Columns.PreferredWidthType = wdPreferredWidthPoints
- .Columns.PreferredWidth = CentimetersToPoints(cw)
- .Rows.HeightRule = wdRowHeightExactly
- .Rows.Height = CentimetersToPoints(rh)
- End With
- .EndKey Unit:=6
- For k = 1 To tpsl
- Select Case k
- Case 1
- Tb.Cell(1, 1).Select: .MoveLeft , 1
- Set Pic = .InlineShapes.AddPicture(FileName:=E & "" & brr(p), LinkToFile:=False, SaveWithDocument:=True)
- Pic.LockAspectRatio = False
- Pic.Height = Tb.Rows(1).Height - 2
- Pic.Width = Tb.Columns(1).Width - 2
- Case 2
- Tb.Cell(1, 2).Select: .MoveLeft , 1
- Set Pic = .InlineShapes.AddPicture(FileName:=E & "" & brr(p), LinkToFile:=False, SaveWithDocument:=True)
- Pic.LockAspectRatio = False
- Pic.Height = Tb.Rows(1).Height
- Pic.Width = Tb.Columns(2).Width - 2
- Case 3
- Tb.Cell(2, 1).Select: .MoveLeft , 1
- Set Pic = .InlineShapes.AddPicture(FileName:=E & "" & brr(p), LinkToFile:=False, SaveWithDocument:=True)
- Pic.LockAspectRatio = False
- Pic.Height = Tb.Rows(1).Height
- Pic.Width = Tb.Columns(1).Width - 2
- Case 4
- Tb.Cell(2, 2).Select: .MoveLeft , 1
- Set Pic = .InlineShapes.AddPicture(FileName:=E & "" & brr(p), LinkToFile:=False, SaveWithDocument:=True)
- Pic.LockAspectRatio = False
- Pic.Width = Tb.Columns(2).Width - 2
- Pic.Height = Tb.Rows(1).Height
- End Select
- p = p + 1
- Next
- .EndKey Unit:=6
- Next
- ''''''''''''''''''''''''''''''''''
- '加入以下这个循环
- For Each t In Nd.Tables
- If t.Range.Columns.Count > 1 Then t.Range.Cells.DistributeWidth
- Next
- ''''''''''''''''''''''''''''''''''''''''''''
- End With
- Nd.SaveAs2 E & ".docx", fileformat:=16
- Next
- Application.ScreenUpdating = True
- MsgBox "整理完事,个别图片需要手工调整一下即可。"
- End Sub
复制代码 |
|