|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Option Explicit
Sub TEST()
Dim i&, j&, dic As Object, strPath$, strFileName$, strPicName$, Pic As InlineShape
strPath = ThisDocument.Path & "\"
With Application.FileDialog(4)
.InitialFileName = strPath
If .Show Then strPath = .SelectedItems(1) & "\" Else Exit Sub
End With
Set dic = CreateObject("Scripting.Dictionary")
strFileName = Dir(strPath & "*.jpg")
Do Until strFileName = ""
strPicName = Left(strFileName, InStrRev(strFileName, ".") - 1)
dic(strPicName) = strPath & strFileName
strFileName = Dir
Loop
If dic.Count = 0 Then MsgBox "未发现图片文件,请重新选择": Exit Sub
Application.ScreenUpdating = False
With ActiveDocument
For Each Pic In .InlineShapes
Pic.Delete
Next
With .Tables(1)
ReDim br(2 To .Columns.Count)
For j = 2 To UBound(br)
br(j) = Left(.Cell(1, j).Range.Text, Len(.Cell(1, j).Range.Text) - 2)
Next j
For i = 2 To .Rows.Count
strPicName = Left(.Cell(i, 1).Range.Text, Len(.Cell(i, 1).Range.Text) - 2)
For j = 2 To .Columns.Count
If dic.Exists(strPicName & br(j)) Then
With .Cell(i, j).Range.InlineShapes.AddPicture(dic(strPicName & br(j)))
.LockAspectRatio = True
.Height = 100
End With
End If
Next j
Next i
End With
End With
Application.ScreenUpdating = True
End Sub
|
评分
-
2
查看全部评分
-
|