AddShape 方法 (Excel)Shapes.AddShape method (Excel)

返回一个**Shape** 对象, 该对象代表工作表上的新的自选图形。Returns a Shape object that represents the new AutoShape on a worksheet.

语法Syntax

表达式AddShape(键入宽度高度)expression.AddShape (Type, Left, Top, Width, Height)

expression:一个表示 Shapes 对象的变量。expression A variable that represents a Shapes object.

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
TypeType 必需Required MsoAutoShapeTypeMsoAutoShapeType 指定要创建的自选形状的类型。Specifies the type of AutoShape to create.
LeftLeft 必需Required SingleSingle 自选图形边界框左上角相对于文档左上角的位置 (以为单位)。The position (in points) of the upper-left corner of the AutoShape's bounding box relative to the upper-left corner of the document.
TopTop 必需Required SingleSingle 自选图形边框左上角相对于文档顶部的位置 (以磅为单位)。The position (in points) of the upper-left corner of the AutoShape's bounding box relative to the top of the document.
WidthWidth 必需Required SingleSingle 自选形状边框的宽度(以磅为单位)。The width of the AutoShape's bounding box, in points.
HeightHeight 必需Required SingleSingle 自选形状边框的高度(以磅为单位)。The height of the AutoShape's bounding box, in points.

返回值Return value

ShapeShape

备注Remarks

若要更改已添加的自选图形的类型, 请设置**AutoShapeType** 属性。To change the type of an AutoShape that you have added, set the AutoShapeType property.

示例Example

本示例向 myDocument 中添加矩形。This example adds a rectangle to myDocument.

Set myDocument = Worksheets(1) 
myDocument.Shapes.AddShape msoShapeRectangle, 50, 50, 100, 200

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.