+ Reply to Thread
Results 1 to 5 of 5

Why can't I delete this shape now?

  1. #1
    JK
    Guest

    Why can't I delete this shape now?

    I have been using the following code to delete a shape for the the past
    several years.

    Option Explicit

    Sub ClearPicture()

    'DELETE IMAGE MKTPKG

    Dim X As Shape

    On Error Resume Next

    Set X = Sheets("MktPkg").Shapes(1)

    If Err = 0 Then

    X.Delete

    End If

    End Sub



    In fact, it still works on one version of my software, but on the other it
    mysteriously stopped working. The shape gets pasted to the worksheet just
    fine, but now, for some reason, it won't delete. I've tried cleaning my code
    with Rob Bovey's code cleaner, but it still doesn't execute. When I remove
    the On Error Resume Next, the message says Application-defined or
    application-defined error.



    What happened? Even for all the changes I've been making to the program, I
    never touched this.



    Please help if you can. Thank you.



    Jim Kobzeff



  2. #2
    Vic Eldridge
    Guest

    RE: Why can't I delete this shape now?

    Hi Jim,

    A protected worksheet could cause that error. Is that the problem ?


    Regards,
    Vic Eldridge


    "JK" wrote:

    > I have been using the following code to delete a shape for the the past
    > several years.
    >
    > Option Explicit
    >
    > Sub ClearPicture()
    >
    > 'DELETE IMAGE MKTPKG
    >
    > Dim X As Shape
    >
    > On Error Resume Next
    >
    > Set X = Sheets("MktPkg").Shapes(1)
    >
    > If Err = 0 Then
    >
    > X.Delete
    >
    > End If
    >
    > End Sub
    >
    >
    >
    > In fact, it still works on one version of my software, but on the other it
    > mysteriously stopped working. The shape gets pasted to the worksheet just
    > fine, but now, for some reason, it won't delete. I've tried cleaning my code
    > with Rob Bovey's code cleaner, but it still doesn't execute. When I remove
    > the On Error Resume Next, the message says Application-defined or
    > application-defined error.
    >
    >
    >
    > What happened? Even for all the changes I've been making to the program, I
    > never touched this.
    >
    >
    >
    > Please help if you can. Thank you.
    >
    >
    >
    > Jim Kobzeff
    >
    >
    >


  3. #3
    Patrick Molloy
    Guest

    RE: Why can't I delete this shape now?

    you may have the sheet protected

    the code is tidied up...

    Sub ClearPicture()

    With ActiveSheet.Shapes
    If .Count > 0 Then
    .Item(1).Delete
    End If
    End With

    End Sub

    "JK" wrote:

    > I have been using the following code to delete a shape for the the past
    > several years.
    >
    > Option Explicit
    >
    > Sub ClearPicture()
    >
    > 'DELETE IMAGE MKTPKG
    >
    > Dim X As Shape
    >
    > On Error Resume Next
    >
    > Set X = Sheets("MktPkg").Shapes(1)
    >
    > If Err = 0 Then
    >
    > X.Delete
    >
    > End If
    >
    > End Sub
    >
    >
    >
    > In fact, it still works on one version of my software, but on the other it
    > mysteriously stopped working. The shape gets pasted to the worksheet just
    > fine, but now, for some reason, it won't delete. I've tried cleaning my code
    > with Rob Bovey's code cleaner, but it still doesn't execute. When I remove
    > the On Error Resume Next, the message says Application-defined or
    > application-defined error.
    >
    >
    >
    > What happened? Even for all the changes I've been making to the program, I
    > never touched this.
    >
    >
    >
    > Please help if you can. Thank you.
    >
    >
    >
    > Jim Kobzeff
    >
    >
    >


  4. #4
    Nigel
    Guest

    Re: Why can't I delete this shape now?

    maybe a protected sheet, also using the err object as a control is possibly
    a problem. On Error Resume Next clears the error stack, so if your If err
    statement is dealt with differently. What versions of Excel are you testing
    in?

    --
    Cheers
    Nigel



    "JK" <[email protected]> wrote in message news:Le_De.11686$JJ.9892@trnddc09...
    > I have been using the following code to delete a shape for the the past
    > several years.
    >
    > Option Explicit
    >
    > Sub ClearPicture()
    >
    > 'DELETE IMAGE MKTPKG
    >
    > Dim X As Shape
    >
    > On Error Resume Next
    >
    > Set X = Sheets("MktPkg").Shapes(1)
    >
    > If Err = 0 Then
    >
    > X.Delete
    >
    > End If
    >
    > End Sub
    >
    >
    >
    > In fact, it still works on one version of my software, but on the other it
    > mysteriously stopped working. The shape gets pasted to the worksheet just
    > fine, but now, for some reason, it won't delete. I've tried cleaning my

    code
    > with Rob Bovey's code cleaner, but it still doesn't execute. When I remove
    > the On Error Resume Next, the message says Application-defined or
    > application-defined error.
    >
    >
    >
    > What happened? Even for all the changes I've been making to the program, I
    > never touched this.
    >
    >
    >
    > Please help if you can. Thank you.
    >
    >
    >
    > Jim Kobzeff
    >
    >




  5. #5
    JK
    Guest

    Re: Why can't I delete this shape now?

    Thank you group. A combination of adding Worksheet.Unprotect and Patrick's
    tidied up procedure, got it working.

    "JK" <[email protected]> wrote in message news:Le_De.11686$JJ.9892@trnddc09...
    >I have been using the following code to delete a shape for the the past
    >several years.
    >
    > Option Explicit
    >
    > Sub ClearPicture()
    >
    > 'DELETE IMAGE MKTPKG
    >
    > Dim X As Shape
    >
    > On Error Resume Next
    >
    > Set X = Sheets("MktPkg").Shapes(1)
    >
    > If Err = 0 Then
    >
    > X.Delete
    >
    > End If
    >
    > End Sub
    >
    >
    >
    > In fact, it still works on one version of my software, but on the other it
    > mysteriously stopped working. The shape gets pasted to the worksheet just
    > fine, but now, for some reason, it won't delete. I've tried cleaning my
    > code with Rob Bovey's code cleaner, but it still doesn't execute. When I
    > remove the On Error Resume Next, the message says Application-defined or
    > application-defined error.
    >
    >
    >
    > What happened? Even for all the changes I've been making to the program, I
    > never touched this.
    >
    >
    >
    > Please help if you can. Thank you.
    >
    >
    >
    > Jim Kobzeff
    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1