表示 Project 报表中的对象,例如图表、报表、文本框、任意多边形绘图或图片。
备注
Shape 对象是 Shapes 集合的成员,该集合包括报表中的所有形状。
注意
未实现 Shape 对象的宏记录。 也就是说,在 Project 中录制宏并手动添加形状或编辑形状元素时,不会记录添加和操作形状的步骤。
有三个对象表示形状:“ 形状 ”集合,表示文档上的所有形状; ShapeRange 对象,表示文档上指定的形状子集 (例如, ShapeRange 对象可以表示文档上的形状 1 和 4,也可以表示文档) 上的所有选定形状;以及表示文档中单个形状的 Shape 对象。 如果您需要同时处理几个形状,或处理选定区域中的多个形状,请使用 ShapeRange 集合。
使用 Shapes(Index),其中 Index 是形状名称或索引编号,返回单个 Shape 对象。
示例
在下面的示例中, TestTextShape 宏创建了一个文本框形状,添加了一些文本,并更改了形状样式、填充、线条、阴影和反射属性。 FlipShape 宏从上到下翻转形状。
Sub TestTextShape()
Dim theReport As Report
Dim textShape As Shape
Dim reportName As String
reportName = "Simple scalar chart"
Set theReport = ActiveProject.Reports(reportName)
Set textShape = theReport.Shapes.AddTextbox(msoTextOrientationHorizontal, 30, 30, 300, 100)
textShape.Name = "TestTextBox"
textShape.TextFrame2.TextRange.Characters.Text = "This is a test. It's only a test. " _
& "If it had been real information, there would be some real text here."
textShape.TextFrame2.TextRange.Characters(1, 15).ParagraphFormat.FirstLineIndent = 0
' Set the font for the first 15 characters to dark blue bold.
With textShape.TextFrame2.TextRange.Characters(1, 15).Font
.Fill.Visible = msoTrue
.Fill.ForeColor.ObjectThemeColor = msoThemeColorAccent5
.Fill.Transparency = 0
.Fill.Solid
.Size = 14
.Bold = msoTrue
End With
textShape.ShapeStyle = msoShapeStylePreset42
With textShape.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 255, 0)
.Transparency = 0
'.Solid
End With
With textShape.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorText1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
End With
textShape.Shadow.Type = msoShadow22
textShape.Reflection.Type = msoReflectionType3
End Sub
Sub FlipShape()
Dim theReport As Report
Dim theShape As Shape
Dim reportName As String
Dim shapeName As String
reportName = "Simple scalar chart"
shapeName = "TestTextBox"
Set theShape = ActiveProject.Reports(reportName).Shapes(shapeName)
theShape.Flip msoFlipVertical
theShape.Select
End Sub
图 1 显示了结果,其中选择形状以使“绘图工具”下的功能区“格式”选项卡可用,尽管活动选项卡是“报表工具”下的“设计”。 如果未选择该形状,则“ 绘图工具 ”和“ 格式 ”选项卡将不可见。
图 1. 测试形状对象模型
方法
| 名称 |
|---|
| Apply |
| Copy |
| Cut |
| 删除 |
| Duplicate |
| Flip |
| IncrementLeft |
| IncrementRotation |
| IncrementTop |
| PickUp |
| RerouteConnections |
| ScaleHeight |
| ScaleWidth |
| Select |
| SetShapesDefaultProperties |
| Ungroup |
| ZOrder |
属性
另请参阅
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。