+ Reply to Thread
Results 1 to 8 of 8

Thread: not deleting pictures in 2010 version

  1. #1
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    325

    not deleting pictures in 2010 version

    I have the code below which deletes a number of pictures along a specific row. This works OK using office 2003 but not with 2010. I suspect it may be something to do with object references but am not sure what to select

           With Worksheets("pictures")
       For Each Sh In .Shapes
           If Not Application.Intersect(Sh.TopLeftCell, .rows(sourcerow)) Is Nothing Then
             If Sh.Type = msoPicture Then Sh.Delete
           End If
        Next Sh
    End With
    Last edited by tryer; 04-30-2011 at 01:54 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    325

    Re: not deleting pictures in 2010 version

    I have been doing some research and experimenting on this and have discovered it is something to do with enums (unfortunately I don't know what enums are)
    However when runnung the code as it is msoPicture = 13 as such it deletes the pictures in excel 2003 but not with excel 2010. If I substitute msoPicture for 11 then it works OK in excel 2010

    So my next question would be from where does it get the value 13 assigned to msoPicture and can i change this.

    Obviously I can just substitute all instances of msoPicture with 11 and it will work in 2010 but then wont work if used with 2003

    Any help or suggestions would be much appreciated.
    In the meantime it looks like I have some more research to do to find out more about enums

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    11,351

    Re: not deleting pictures in 2010 version

    The enum are part of the Office library. Use can use Object browser in VBE to see them.

    msoPicutre has a value of 13 in xl2010, same as xl2003.

    If your code works when changing the value to 11 then the shape type is actually msoLinkedPicture
    Cheers
    Andy
    www.andypope.info

  4. #4
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    325

    Re: not deleting pictures in 2010 version

    Quote Originally Posted by Andy Pope View Post
    The enum are part of the Office library. Use can use Object browser in VBE to see them.

    msoPicutre has a value of 13 in xl2010, same as xl2003.

    If your code works when changing the value to 11 then the shape type is actually msoLinkedPicture
    Andy,
    Thanks for the answer. It certainly does work when changing to 11.
    so what is an msoLinkedPicture? and would I be better using simply 11 or should I use msoLinkedPicture?

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    11,351

    Re: not deleting pictures in 2010 version

    You are better of using the enum msoLinkedPicture. You probably need to expand your code to include a test for both picture and linked picture.
    Cheers
    Andy
    www.andypope.info

  6. #6
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    325

    Thumbs up Re: not deleting pictures in 2010 version

    Sorry to resurect this post but could someone please help with this again.

    As per Andy's suggestion I am trying to test for both msoPicture and msoLinkedPicture,
    I have tried the code below but get an error on the msoLinkedPicture line when using excel 2003 though it works OK on 2010

    if I change msoPicture to the number 11 and msolinkedpicture to 13 then it works OK in 2003 but not in 2010

    I'm trying to get it to work in both !

          With Worksheets("pictures")
       For Each Sh In .Shapes
           If Not Application.Intersect(Sh.TopLeftCell, .rows(sourcerow)) Is Nothing Then
             If Sh.Type = msoPicture Then Sh.Delete
             If Sh.Type = msoLinkedPicture Then Sh.Delete
    
           End If
        Next Sh
    End With

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    11,351

    Re: not deleting pictures in 2010 version

    If the first test successeds then the object Sh will not have a valid reference.

       For Each Sh In .Shapes
           If Not Application.Intersect(Sh.TopLeftCell, .rows(sourcerow)) Is Nothing Then
             If Sh.Type = msoPicture Then 
                Sh.Delete
             elseIf Sh.Type = msoLinkedPicture Then 
                Sh.Delete
           End If
        Next Sh
    Cheers
    Andy
    www.andypope.info

  8. #8
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    325

    Re: not deleting pictures in 2010 version

    sorry for not replying earlier I have only just logged back on
    Andy, thank you so much for the answer, it solves the problem

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