|
Option Explicit
Sub test()
Dim ar(), br, i&, j&, r&, strPath$, strFileName$, strSaveName$
strPath = ThisDocument.Path & "\"
With Application.FileDialog(4)
.InitialFileName = strPath
If .Show Then strPath = .SelectedItems(1) & "\" Else Exit Sub
End With
strFileName = Dir(strPath & "*.png")
Do Until strFileName = ""
r = r + 1
ReDim Preserve ar(1 To 2, 1 To r)
ar(1, r) = strFileName: ar(2, r) = strPath & strFileName
strFileName = Dir
Loop
If r = 0 Then MsgBox "未发现图片文件,请重新选择": Exit Sub
strFileName = ThisDocument.Path & "\" & "数据验收报告模板.docx"
If Dir(strFileName) = "" Then MsgBox "模板文件不存在,请检查!", vbExclamation: Exit Sub
Application.ScreenUpdating = False
br = Array("地库场景:", "城区场景:", "高速场景:")
With Documents.Open(strFileName)
strSaveName = ThisDocument.Path & "\" & "数据验收报告"
For i = 0 To UBound(br)
With .Content.Find
.Execute FindText:=br(i), Forward:=True
If .Found Then
.Parent.Select
With Selection
.Collapse 0: .InsertBreak (6)
For j = 1 To UBound(ar, 2)
If InStr(ar(1, j), Left(br(i), 2)) Then
.InlineShapes.AddPicture ar(2, j), , True
End If
Next j
End With
End If
End With
Next i
.SaveAs strSaveName
.Close
End With
Application.ScreenUpdating = True
End Sub
|
评分
-
2
查看全部评分
-
|