excel 2007 image doesn't go to back

2019-08-30 09:59发布

I have an image on an excel 2007 workbook, with some text boxes on top. The image and text changes every 5 minutes approx with some VBA code I put behind.

The image object has been sent to back, so the text boxes should be shown on top...but for some strange reason, it doesn't.

it works fine in excel 2003, but not in 2007.

Anyone knows why and, most importantly, is there a way of fixing what appears to be a bug ?.

Note that I have tried also to insert an image instead (from Insert>Image) and that works (the text is on top of image), however it is a different type of object and I cannot make the VBA code work with this type of image object.

I have tried the following code I found in the forum, but some how I am unable to name the image as "Image_2" so nothing happens. I use a random selector (photo_array(rrr)) to change the image and text automatically.

Thanks in advance

            strPic = "Image_2"
            Set shp = WS.Shapes(strPic)

            'Capture properties of exisitng picture such as location and size
            With shp
                t = .Top
                l = .Left
                h = .Height
                w = .Width
            End With

            WS.Shapes(strPic).Delete

            Set shp = WS.Shapes.AddPicture(ThisWorkbook.Path & "\images\" & photo_array(rrr), msoFalse, msoTrue, l, t, w, h)
            shp.Name = "Image_2"  ' strPic
            shp.ScaleHeight Factor:=1, RelativeToOriginalSize:=msoTrue
            shp.ScaleWidth Factor:=1, RelativeToOriginalSize:=msoTrue

标签: image excel
1条回答
2楼-- · 2019-08-30 10:23

Since you keep adding a new picture, it is being put on the top of the ZOrder by default.

Try adding this line at the end:

shp.ZOrder msoSendToBack

This should put the picture back where you want it to be... in the back.

查看更多
登录 后发表回答