|
本帖最后由 duquancai 于 2018-6-7 13:39 编辑
Sub main()
Dim k$, p As Paragraph, mypath$, doc As Document
Set doc = ActiveDocument
If doc.ListParagraphs.Count < 1 Then Exit Sub
mypath = ThisDocument.Path & "\照片信息\"
Call Preprocessing(doc)
For Each p In doc.ListParagraphs
If p.Range.ListFormat.ListLevelNumber = 3 Then
k = Replace(Replace(p.Range.Text, vbCr, ""), " ", "")
With p.Range
.Collapse 0: .Text = vbCr: .Collapse: .Style = "正文"
If Len(Dir(mypath & k & "_身份证正面.jpg")) Then
Call InsetPicture(.Duplicate, mypath & k & "_身份证正面.jpg")
.Start = .End + 1
End If
If Len(Dir(mypath & k & "_身份证背面.jpg")) Then
Call InsetPicture(.Duplicate, mypath & k & "_身份证背面.jpg")
End If
End With
End If
Next
MsgBox "OK!"
End Sub
Sub Preprocessing(doc As Document)
If doc.InlineShapes.Count > 0 Then
For i = doc.InlineShapes.Count To 1 Step -1
doc.InlineShapes(i).Delete
Next
End If
doc.Content.Find.Execute "^13{2,}", , , -1, , , , , , "^p", 2
End Sub
Sub InsetPicture(rang As Range, pf)
With rang.InlineShapes.AddPicture(pf, 0, True)
.Width = CentimetersToPoints(8.2)
.Height = CentimetersToPoints(5.2)
End With
End Sub
|
|