By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 2,042 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

check if shape exists in worksheet

P: 8
I have a workbook open function and want to perform a task only if a certain shape has been deleted. Below is the gist of my code.

Expand|Select|Wrap|Line Numbers
  1. With Sheets("JCS")
  2.     If ActiveSheet.Shapes("Rounded Rectangle 1") = 0 Then
  3.         .Protect Password:="secret", UserInterfaceOnly:=True
  4.         .EnableOutlining = True
  5.     Else
  6.  
  7.     End If
  8. End With
I have tried having it equal 0 and also False and can't quite seem to figure it out. Any suggestions?
Sep 17 '07 #1
Share this Question
Share on Google+
3 Replies


kadghar
Expert 100+
P: 1,295
I have a workbook open function and want to perform a task only if a certain shape has been deleted. Below is the gist of my code.

With Sheets("JCS")
If ActiveSheet.Shapes("Rounded Rectangle 1") = 0 Then

.Protect Password:="secret", UserInterfaceOnly:=True
.EnableOutlining = True

Else

End If

End With

I have tried having it equal 0 and also False and can't quite seem to figure it out. Any suggestions?
try checking each shape
Expand|Select|Wrap|Line Numbers
  1. dim boo1 as boolean
  2. for i = 1 to activesheet.shapes.count
  3.     if activesheet.shapes(i).name = "Rounded Rectangle 1" then boo1 = true
  4. next
  5. if boo1=true then
  6.     'What happens if the shape exists
  7. else
  8.     'What happens if it doesnt
  9. end if
HTH
Sep 17 '07 #2

Expert 5K+
P: 8,434
...
If ActiveSheet.Shapes("Rounded Rectangle 1") = 0 Then
...
I have tried having it equal 0 and also False and can't quite seem to figure it out.
Just a note. Most likely, the Shapes collection is returning a Shape object, not a boolean or a number. It might be possible to check whether it returned Nothing, or Null. Or perhaps it actually generates an "item not found" type of error, which is being picked up by your error-handling code in some way?
Sep 18 '07 #3

P: 8
thanks, kadghar. it worked perfectly for my application.

Also, my error handling was skipping the error I got with my previous code.
Sep 18 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.