运行代码以识别单元格中是否存在图片/图像时,Excel会不断崩溃,即使我一步一步运行它也不会运行代码。
我尝试使用shape.name,但结果相同。 你们能想到解决方法吗? 我的电子表格包含530行,其中约20%没有图片,我需要在每个“产品”中添加一个 我将以下循环从行= 2应用于行= 530
我根据此页面尝试了替代方法,但是代码不断崩溃: How to check whether any of shapes exists?
Dim rngCell As Range
Dim shp As Shape
Dim objPic As Picture
Dim Pic_bool As Boolean
Dim strFolder As String
Dim strFileName As String
Prod_name = Range("F" & i)
strFolder = "C:Documents/Pictures"
strFileName = strFolder & Prod_name & ".png"
Pic_bool = False
Set rngCell = Range("H" & i)
For Each shp In ActiveSheet.Shapes 'Excel crashes on this line
If shp.TopLeftCell.Address = rngCell.Address Then
If shp.Name = strFileName Then
Pic_bool = True
Exit For
End If
Next shp
If Pic_bool <> True Then
'Insert picture on Cell H&i
If Dir(strFileName) <> "" Then
Range("H" & i) = "No Picture Found"
End If
End If
预期结果是H列中的每一行都会验证图片是否已存在,否则将插入图片