gpt4 book ai didi

vba - 使用vba从单元格中删除图片

转载 作者:行者123 更新时间:2023-12-02 14:31:14 25 4
gpt4 key购买 nike

我想使用宏在单元格中复制新图片,但在复制新图片之前,我如何检查该特定单元格是否已经有图片,将 shape.TopLeftCell 与当前单元格匹配为 不为我工作,任何帮助将不胜感激!

' this is not working for every picture
Sub DeleteCell(curcell) 'curcell=ActiveWindow.ActiveCell

Dim sh As Shapes

For Each sh In ActiveSheet.Shapes
If sh.TopLeftCell.Address = curcell.Cells.Address Then
sh.Delete
End If
Next

End Sub

谢谢

最佳答案

  1. Sub DeleteCell(curcell) 更改为 Sub DeleteCell(curcell As Range)
  2. Dim sh As Shapes 更改为 Dim sh As Shape
  3. curcell.Cells.Address 更改为 curcell.Address

所以你的代码看起来像这样

Sub DeleteCell(curcell As Range)  'curcell=ActiveWindow.ActiveCell
Dim sh As Shape

For Each sh In ActiveSheet.Shapes
If sh.TopLeftCell.Address = curcell.Address Then sh.Delete
Next
End Sub

关于vba - 使用vba从单元格中删除图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39283914/

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