Marc
Marc

Reputation: 13

VBA Pictures don't show in Excel 2007

I am confronted with a strange problem which occurs under Excel 2007.

I have created a document with 1000 rows (different products/ article numbers) and fetch the product pictures from the net with my little VBA Code

ActiveSheet.Pictures.Insert(ActiveCell.Text).Select
Selection.ShapeRange.Height = 100

Pictures do show in Excel 2010, even on other PCs However they do not appear in Excel 2007, even in other formats like 97-03

Upvotes: 0

Views: 640

Answers (1)

Kazimierz Jawor
Kazimierz Jawor

Reputation: 19077

Try alternative method of adding pictures to excel sheet. It will go as follows:

ActiveSheet.Shapes.AddPicture _
        Filename:=Activecell.Text, _
        linktofile:=msoFalse, _
        savewithdocument:=msoCTrue, _
        Left:=40, Top:=40, Width:=1600, Height:=1600

Few times I've found out it's more stable and reliable method of adding pictures.

Edit As pointed by @Julien Marrec below, using the code I provided you need to know proportion of the shape or you need to adjust it as a next step. I usually do it with this code:

With ActiveSheet.Shapes(ActiveSheet.Count)
    .LockAspectRatio = msoTrue
    .ScaleHeight 1, msoTrue, msoScaleFromTopLeft
    .Width = 200
End With

Important! if you add big picture you need to oversize it when adding (1600 px in the first portion of code). If not you will not be able to get the result of .ScaleHeight method in the second portion of code.

Upvotes: 1

Related Questions