首页 > 解决方案 > 用文本“1”替换单元格中的图像

问题描述

我有一个 excel,每个单元格中有 1 列带有图片,该图片决定了某些内容,但我想将其更改为 1。只有 1 张图片,确切地说,该栏是 J;Name =PO history/release documentation 。有人可以帮我用VBA做吗 谢谢!

Public Sub Replace_Picture()
Const Replace_Text = "OK"
Dim shp as Shape

For Each shp In ActiveSheet.Shapes
If shp.TopLeftCell.Address = shp.BottomRightCell.Address Then
shp.TopLeftCell.Value = Replace_Text
shp.Delete
End If
Next

Set shp = Nothing
End Sub

我尝试了上面的代码,但它不起作用并且const replace_text是红色的。我只想将那些带有图片的单元格更改为“1”,而那些空白将保持不变。

标签: excelvba

解决方案


我猜你想从 SAP 中删除 PO 历史形状。你可以试试下面的 VBA 代码。另一种方法是您可以直接从 SAP 中“复制+粘贴”数据,而不是“导出到 Excel”

Sub Replace_Shapes()
Dim Shp As Shape
Dim Shp_Address
For Each Shp In ActiveSheet.Shapes
  If Shp.Type = msoPicture Then
     'Identify the address of Shape by TopLeft
     Shp_Address = Shp.TopLeftCell.Address
     Range(Shp_Address) = 1
     Shp.Delete    
  End If Next
End Sub

推荐阅读