|
根据你提供附件,可以用如下代码实现:
Sub test()
Dim f$, ph$, d As Object, aDoc As Document, tb As Table, c As Cell, pf$
Application.ScreenUpdating = False
Set aDoc = ActiveDocument
If aDoc.Tables.Count = 0 Or aDoc.Tables.Count > 1 Then Exit Sub
ph = ThisDocument.Path: f = Dir(ph & "\*.jpg")
Set d = CreateObject("Scripting.Dictionary")
Do While f <> ""
d(Left(f, InStrRev(f, ".") - 1)) = ph & "\" & f
f = Dir()
Loop
If d.Count = 0 Then Exit Sub
k = d.keys: t = d.items
Set tb = aDoc.Tables(1)
For i = 2 To tb.Columns(3).Cells.Count
With tb.Columns(3).Cells(i).Range
.End = .End - 1
If d.Exists(.Text) Then
pf = d(.Text)
.Move 12, 4: .Expand 12: .Text = Empty
.InlineShapes.AddPicture pf, 0, -1
Else
.Move 12, 4: .Expand 12: .Text = Empty
End If
End With
Next
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|