|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Public Sub 图片()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
Dim picW As Single, picH As Single
Dim cellW As Single, cellH As Single
Dim rtoW As Single, rtoH As Single
mypath = "。。。" ' 指定具体的文件夹
picname = Dir(mypath & "。。。")'图片名称
Range("B6:H18").Select'选择插入图片的单元格
ActiveSheet.Pictures.Insert(mypath & picname).Select
Selection.ShapeRange.LockAspectRatio = msoFalse '取消比例锁定
cellW = ActiveCell.MergeArea.Width
cellH = ActiveCell.MergeArea.Height
picW = Selection.ShapeRange.Width
picH = Selection.ShapeRange.Height
rtoW = cellW / picW
rtoH = cellH / picH
Selection.ShapeRange.ScaleWidth rtoW, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight rtoH, msoFalse, msoScaleFromTopLeft
Selection.Cut
ActiveSheet.Pictures.Paste
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
这个是我自己用的,加了简单的注释,你自己按需要修改一下。 |
|