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

标签 vba excel

我想使用宏在单元格中复制新图片,但在复制新图片之前,我如何检查该特定单元格是否已经有图片,将 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/

相关文章:

Excel VBA 帮助文档安装

ms-access - VBA检查对象是否已设置

excel - 使用 VBA 宏 + 按钮在 Excel 工作表中前后移动,按顺序隐藏工作表会破坏功能

json - 在 VBA 中发送 JSON POST 请求

excel apache poi 开头的 Java 插入表

vba - 根据字符串内容对组下的每个字符串进行分类(1 次)? (Excel)

vba - Excel公式单元格基于背景颜色

excel - 问: How to clear cells after archiving?

excel - 将粘贴制表符分隔的结果复制到 excel 文件中

vba - 尝试通过 Excel VBA 宏保存 GIF 屏幕截图时出错