|
Option Explicit
Sub test()
Dim ar(), i&, p$, f, n&, strFileName$, strExtName$, dic As Object, shp As Shape
p = ThisWorkbook.Path & "\"
With Application.FileDialog(4)
.InitialFileName = p
.AllowMultiSelect = True
If .Show Then p = .SelectedItems(1) & "\" Else Exit Sub
End With
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
For Each shp In ActiveSheet.Shapes
If shp.Type = 11 Then shp.Delete
Next
With CreateObject("VBScript.RegExp")
.Pattern = "jpg|jpep|png|gif|bmp|gif"
.IgnoreCase = True
For Each f In CreateObject("Scripting.FileSystemObject").GetFolder(p).Files
strExtName = Mid(f.Name, InStrRev(f.Name, ".") + 1)
strFileName = Left(f.Name, InStrRev(f.Name, ".") - 1)
If .test(strExtName) Then
dic(strFileName) = f.Path
End If
Next
End With
With Range("C11", Cells(Rows.Count, "C").End(xlUp))
ar = .Value
For i = 1 To UBound(ar)
If dic.exists(ar(i, 1)) Then
n = IIf(i Mod 5 = 0, 5, i Mod 5)
.Cells(i, 17 + n).Select
ActiveSheet.Pictures.Insert(dic(ar(i, 1))).Select
With Selection
.ShapeRange.LockAspectRatio = msoFalse
.Height = ActiveCell.RowHeight * 5
.Width = ActiveCell.Width
.Placement = xlMoveAndSize
End With
End If
Next i
End With
Application.ScreenUpdating = True
Beep
End Sub
|
评分
-
1
查看全部评分
-
|