|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub qs() '2024/6/30图片自适应单元格大小
Dim fso As Object, folderPath As String, fileName As String, file As Object
Dim ws As Worksheet, rw, sp As Shape
For Each sp In ActiveSheet.Shapes
If sp.Type <> 8 Then
sp.Delete
End If
Next sp
Set fso = CreateObject("Scripting.FileSystemObject")
folderPath = ThisWorkbook.Path & "\花\"
Set ws = ActiveSheet
rw = 0
For Each file In fso.GetFolder(folderPath).Files
rw = rw + 1
x = Mid(file, VBA.InStrRev(file, "\") + 1, Len(file) - InStrRev(file, "\") - 4)
ws.Cells(rw, 1).Value = x
With ws.Cells(rw, 1).Offset(0, 1)
Z = .Left
d = .Top
k = .Width
g = .Height
ws.Shapes.AddPicture file, 1, 1, Z, d, k, g
End With
Next file
Set fso = Nothing
Set file = Nothing
Set ws = Nothing
MsgBox "完成"
End Sub |
|