Name

shapes.AddPicture(Filename, LinkToFile, SaveWithDocument, Left, Top, Width, Height)

Synopsis

Adds a picture to a worksheet or chart and the picture’s Shape object.

Argument

Settings

Filename

The picture file to load.

LinkToFile

True links the shape to the picture file; False copies the image into the file.

SaveWithDocument

True saves the image in the workbook; False saves only link information in the document. If LinkToFile is False, SaveWithDocument must be True.

Left

The horizontal position of the shape in points.

Top

The vertical position of the shape in points.

Width

The width of the shape in points.

Height

The height of the shape in points.

Excel scales the image to fit the Width and Height arguments. To restore the image’s actual height and width, use the ScaleHeight and ScaleWidth methods as shown here:

Sub DrawPicture( )
    Dim ws As Worksheet, s As Shape
    Set ws = ActiveSheet
    ' Insert the image.
    Set s = ws.Shapes.AddPicture(ThisWorkbook.Path & "\logo.bmp", _
      False, True, 100, 100, 1, 1)
    ' Use picture's height and width.
    s.ScaleHeight 1, msoCTrue
    s.ScaleWidth 1, msoCTrue
End Sub

Use the PictureFormat property to control a picture’s brightness, contrast, and transparency.

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.