Reputation: 101
In Excel, if I add a shape to a sheet and then delete it, the shape object still remains in memory. Is there a way to redraw that shape? Please see the code below for reference.
Sub DrawTest()
Dim x As Excel.Shape
Set x = ActiveSheet.Shapes.AddLine(100, 100, 200, 200)
Debug.Print (x Is Nothing) & " " & ObjPtr(x) 'Returns: False 39620608
x.Delete
Debug.Print (x Is Nothing) & " " & ObjPtr(x) 'Returns: False 39620608
'
' Can I redraw it, at this point?? '
'
Set x = Nothing
Debug.Print (x Is Nothing) & " " & ObjPtr(x) 'Returns: True 0
End Sub
Upvotes: 0
Views: 500
Reputation: 771
No, you cannot redraw that shape.
Also, the actual shape does not remain in memory, but the variable x is still allocating the space for that shape.
Therefore, x is still Not Nothing and, will be until you set its reference to nothing (as you did before the last Debug.Print statement)
Sorry for the bad news.
Upvotes: 1
Reputation: 366
The Microsoft help states that the shape.delete method is for deleting the shape. If you want to use the shape later then the .visible =true/false might help?
Upvotes: 0