【发布时间】:2017-10-02 15:48:14
【问题描述】:
我正在处理五张图片(打印屏幕形状)并希望将它们放置在选定的单元格中,例如。细胞 N21、P21、S21、U21 和 W21。我有下面的 VBA 代码来裁剪五张图片/形状,它工作正常,但我不确定如何将它们放在上面选定的单元格中。任何人都可以启发我吗?另外,如何用VBA按钮删除五张图片?
Sub CropPictures()
Application.ScreenUpdating = False
Dim shp As Shape
Dim sngMemoLeft As Single
Dim sngMemoTop As Single
Dim i As Integer, j As Integer
i = 0: j = 0
For Each shp In ActiveSheet.Shapes
i = i + 1
With shp
If .Type = 13 Or .Type = 15 Then
j = j + 1
sngMemoLeft = .Left
sngMemoTop = .Top
With .PictureFormat
.CropLeft = 20
.CropTop = 195
.CropBottom = 27
.CropRight = 565
End With
With shp
.Height = 20
.Width = 195
End With
.Left = sngMemoLeft
.Top = sngMemoTop
End If
End With
Next shp
End Sub
【问题讨论】:
-
您已经在使用
.Left和.Top移动图片。如果您希望它们位于单元格内,则 does not happen. -
嗨,谢谢分享,现在裁剪图片进入我选择的单元格,我可以细化一个单元格范围并将它们一一放置吗?
-
不要在另一个
with shp中使用with shp.... 删除内部with shp和突出.height和.width以与.left相同 -
好的,谢谢分享