gpt4 book ai didi

Excel VBA裁剪图片/形状并放入单元格

转载 作者:行者123 更新时间:2023-12-04 20:33:19 24 4
gpt4 key购买 nike

我正在处理五张图片(打印屏幕形状),并希望将它们放置在选定的单元格中,例如。细胞 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

最佳答案

可以如下图所示定位pic into excel at specific cell这可以通过将形状的左上角属性设置为单元格引用来实现。

假设您要删除事件工作表中的所有形状,您将按照以下方式放置一些内容:

Dim shp As Excel.shape

For Each shp In ActiveSheet.Shapes
shp.Delete
Next

如果特定的 5 个形状,您可以使用相同的结构,但测试形状是否具有特定名称,然后删除。
If shp.Name = "Shape1" Then 
shp.Delete
End If

我也更喜欢明确命名我的图片,例如myPict.Name = "Pic1"这避免了以后跟踪形状编号的问题。

关于Excel VBA裁剪图片/形状并放入单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46520837/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com