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.
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![]()
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
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.
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
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
sorry for not replying earlier I have only just logged back on
Andy, thank you so much for the answer, it solves the problem![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks