如何基于“已将图像粘贴到任何目标单元中的当前工作表中”捕获事件?
Worksheet_Change
的,它在粘贴图像时不会触发。我要弄清楚的是,基本上是在第一个链接中发生的事情(进入Worksheet_Change
事件,并在Change
基于Paste
时继续进行),但是可以还可以检测到Shape
对象已添加到工作表中的事实,其中Shape.Type
是13(根据these enumerations)
非常感谢您的帮助。
示例代码:
Private Sub Worksheet_Change(ByVal Target As Range) 'Doesn't trigger on Image Paste
Dim ws As Worksheet
Dim imageCnt As Integer
Dim sh As Shape
Dim UndoList As String
Set ws = ActiveSheet
UndoList = Application.CommandBars("Standard").Controls("&Undo").List(1)
imageCnt = 0
If Left(UndoList, 5) = "Paste" Then 'When paste.
If Target.Address = "$C$8" Then 'Where user is instructed to paste.
With ws 'Check if there's a new image:
For Each sh In .Shapes
If sh.Type = msoPicture Then
imageCnt = imageCnt + 1
End If
Next sh
If imageCnt > oldImageCnt Then 'oldImageCnt publicly declared elsewhere
Set sh = .Shapes(.Shapes.Count)
'Do stuff with the pasted image here.
End If
End With
End If
End If
End Sub
不幸的是,我不能只是事件沉没Shapes
集合或类似事件。任何建议/帮助都将不胜感激。