|
Sub test()
Dim path$, file$, i%
Application.ScreenUpdating = False
Call delPic
path = ThisWorkbook.path & "\pics\"
file = Dir(path)
Do While file <> ""
i = i + 1
' Call rangeSize(path, file, Cells(i, 1))
Call picSize(path, file, Cells(i, 1))
file = Dir
Loop
End Sub
'
Sub delPic()
ActiveSheet.Pictures.Delete
End Sub
'
'按单元格大小导入
Sub rangeSize(path As String, file As String, rng As Range)
With rng
ActiveSheet.Shapes.AddPicture _
Filename:=path & file, LinkToFile:=True, SaveWithDocument:=True, _
Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height
End With
End Sub
'
'按图片大小导入
Sub picSize(path As String, file As String, rng As Range)
With ActiveSheet.Pictures.Insert(path & file)
'系统限制行高最大值409磅
If .Height < 410 Then rng.RowHeight = .Height Else MsgBox "图片行高超出限制。": End
'图片左上对齐单元格左上
.Left = rng.Left: .Top = rng.Top
'修改区域一列的列宽。从磅转为字符数
rng.ColumnWidth = (.Width * 96 / 72 - 5) / 8
End With
End Sub
导入图片到工作表_4楼.rar
(21 KB, 下载次数: 119)
|
评分
-
1
查看全部评分
-
|