|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Option Explicit
Sub test()
Dim ar$(), i&, strFileName$, strPath$, c&, r&, n&, shp As Shape
strPath = "E:\9月食材图片\"
strFileName = Dir(strPath & "*.png")
Do Until strFileName = ""
n = n + 1
If n > 15 Then Exit Do
ReDim Preserve ar(1 To n)
ar(n) = strPath & strFileName
strFileName = Dir
Loop
If n = 0 Then Exit Sub
Application.ScreenUpdating = False
For Each shp In ActiveSheet.Shapes
If shp.Type = 11 Then shp.Delete
Next
With [G2:K6]
For i = 1 To UBound(ar)
r = (-Int(-(i / 5)) - 1) * 2 + 1
c = IIf(i Mod 5 = 0, 5, i Mod 5)
With .Cells(r, c)
.Select
ActiveSheet.Pictures.Insert(ar(i)).Select
With Selection
.ShapeRange.LockAspectRatio = msoFalse
.Height = ActiveCell.RowHeight ' * 5
.Width = ActiveCell.Width
.Placement = xlMoveAndSize
End With
End With
Next i
End With
Application.ScreenUpdating = True
Beep
End Sub
|
评分
-
2
查看全部评分
-
|