代表 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: Testing the Shape object model
方法
| 名稱 |
|---|
| Apply |
| Copy |
| Cut |
| Delete |
| Duplicate |
| Flip |
| IncrementLeft |
| IncrementRotation |
| IncrementTop |
| PickUp |
| RerouteConnections |
| ScaleHeight |
| ScaleWidth |
| Select |
| SetShapesDefaultProperties |
| Ungroup |
| ZOrder |
屬性
另請參閱
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。