PC Review


Reply
Thread Tools Rate Thread

Check if shape exist

 
 
Hans Hubers
Guest
Posts: n/a
 
      26th May 2008
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.
 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      26th May 2008
Adapt something like:

Sub Macro2()
On Error GoTo placeit:
ActiveSheet.Shapes("Oval 1").Select
MsgBox ("found it")
Exit Sub

placeit:

ActiveSheet.Shapes.AddShape(msoShapeOval, 292.5, 135.75, 100.5, 48#).Select
MsgBox ("made it")
End Sub

--
Gary''s Student - gsnu200788


"Hans Hubers" wrote:

> 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.

 
Reply With Quote
 
Norman Jones
Guest
Posts: n/a
 
      26th May 2008
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" <(E-Mail Removed)> wrote in message
news:BC1A0B31-4F93-48BB-92A5-(E-Mail Removed)...
>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.


 
Reply With Quote
 
Norman Jones
Guest
Posts: n/a
 
      26th May 2008
Hi Hans,

Better would be something like:

'==========>>
Public Sub Tester()
Dim SH As Worksheet
Dim SHP As Shape
Dim Rng As Range
Const sShape As String _
= "Rectangle 1" '<<==== CHANGE

Set SH = ThisWorkbook. _
Sheets("Sheet1") '<<==== CHANGE

With SH
Set Rng = Range("A2") '<<==== CHANGE
On Error Resume Next
Set SHP = .Shapes(sShape)
On Error GoTo 0

If SHP Is Nothing Then
Set SHP = .Shapes.AddShape _
(Type:=msoShapeRectangle, _
Left:=20, _
Top:=50, _
Width:=100, _
Height:=50)
End If
End With

'\\ your code, e.g.:
With SHP
.TextEffect.Text = Range("A1").Value
.Name = sShape
End With
End Sub
'<<==========



---
Regards.
Norman
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check for a shape - then change or delete it if it exists =?Utf-8?B?TW9uYS1BQkU=?= Microsoft Excel Programming 2 30th May 2007 05:37 PM
Check for named shape in chart Fredrik E. Nilsen Microsoft Excel Programming 3 12th Feb 2007 04:03 AM
check whether shape is a group =?Utf-8?B?Q2xhdWRl?= Microsoft Excel Programming 12 31st Aug 2006 01:03 PM
Does Shape Exist? Alan Microsoft Excel Programming 3 24th Jul 2006 01:36 PM
"Shape.Table Object doesn't exist" error when using Automation =?Utf-8?B?bXN0dWVobGVy?= Microsoft Powerpoint 3 20th Jun 2005 04:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:31 AM.