Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88854

Comparing shape object retrieved from Selection and the same shape retrieved from ActiveSheet.Shapes set

$
0
0

I'm trying to check if the Shape selected by user is the proper one. For the simplicity, let's say we have only one shape in otherwise empty worksheet. Because of that, we know that the selected shape must be the right one:

Sub AreShapesTheSame()

    Dim ws As Worksheet
    Set ws = ActiveSheet

    Dim shape As Object
    Dim selShape As Object

    Set shape = ws.Shapes.Item(1).DrawingObject
    Set selShape = Selection

    MsgBox shape Is selShape

End Sub

I can see in the Locals window, that the objects shape and selShape have the same attributes. Also if I change the name of one of them (shape.name = "xxx"), the name of the other object also changes. So I presume, that they are the same objects, or at least referencing the same object.

If that is the case, why is the statement (shape Is selShape) returning False? How can I check if the user Selection is referencing some specific Object?


Viewing all articles
Browse latest Browse all 88854

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>