check if shape exists in worksheet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bertha94
    New Member
    • Aug 2007
    • 8

    check if shape exists in worksheet

    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.

    [CODE=vb]With Sheets("JCS")
    If ActiveSheet.Sha pes("Rounded Rectangle 1") = 0 Then
    .Protect Password:="secr et", UserInterfaceOn ly:=True
    .EnableOutlinin g = True
    Else

    End If
    End With[/CODE]

    I have tried having it equal 0 and also False and can't quite seem to figure it out. Any suggestions?
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by Bertha94
    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.Sha pes("Rounded Rectangle 1") = 0 Then

    .Protect Password:="secr et", UserInterfaceOn ly:=True
    .EnableOutlinin g = 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
    [CODE=vb]dim boo1 as boolean
    for i = 1 to activesheet.sha pes.count
    if activesheet.sha pes(i).name = "Rounded Rectangle 1" then boo1 = true
    next
    if boo1=true then
    'What happens if the shape exists
    else
    'What happens if it doesnt
    end if[/CODE]
    HTH

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by Bertha94
      ...
      If ActiveSheet.Sha pes("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?

      Comment

      • Bertha94
        New Member
        • Aug 2007
        • 8

        #4
        thanks, kadghar. it worked perfectly for my application.

        Also, my error handling was skipping the error I got with my previous code.

        Comment

        Working...