View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones[_2_] Norman Jones[_2_] is offline
external usenet poster
 
Posts: 421
Default Check if shape exist

Hi Hans,

Try something like:

'==========
Public Sub Tester()
Dim SH As Worksheet
Dim SHP As Shape
Const sShape As String = "Rectangle 1"

Set SH = ThisWorkbook.Sheets("Sheet1")

With SH
On Error Resume Next
Set SHP = .Shapes(sShape)
On Error GoTo 0

If Not SHP Is Nothing Then
'\\ your code
Else
Set SHP = .Shapes.AddShape _
(Type:=msoShapeRectangle, _
Left:=20, _
Top:=50, _
Width:=100, _
Height:=50)
End If
End With
End Sub
'<<==========



---
Regards.
Norman


"Hans Hubers" wrote in message
...
I am creating shapes, but the user can delete them. Then if the VBA code
wants to updat the shape with some information in cells, the code should
check if the shape exists and otherwise create it.