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 |
---|---|
|
The picture file to load. |
|
True links the shape to the picture file; False copies the image into the file. |
|
True saves the image in the workbook; False saves only link information in the document. If |
|
The horizontal position of the shape in points. |
|
The vertical position of the shape in points. |
|
The width of the shape in points. |
|
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.