如果您知道Id
例如:
Dim myshape As Shape
myshape.Id = 42
myshape = getShapeById(myshape.Id)
或者,我可以通过Name
获得形状吗?
Dim myshape As Shape
myshape.Name = "Rectangle 42"
myshape = getShapeByName(myshape.Name)
答案 0 :(得分:5)
通过.Name
获取形状.Id
比getting its .Id
by its .Name
更复杂。
但是这是如何完成的:
Sub PrintShapeName()
Debug.Print getNameByID(3, 1)
End Sub
Function getNameByID(shapeID As Long, slide As Integer)
Dim ap As Presentation: Set ap = ActivePresentation
Dim sl As slide: Set sl = ap.Slides(slide)
sl.Shapes.SelectAll
Dim sr As ShapeRange
Set sr = Windows(1).Selection.ShapeRange
Dim s As Shape
For Each s In sr
If s.id = shapeID Then
getNameByID = s.Name
Exit Function
End If
Next
End Function
答案 1 :(得分:3)
要按Shape
获得Name
,请执行以下操作:
Function getShapeByName(shapeName As String, Slide As Integer)
Set getShapeByName = ActivePresentation.Slides(Slide).Shapes(shapeName)
End Function
Dim myshape As Shape
myshape = getShapeByName("Rectangle 42", 1)
答案 2 :(得分:0)
不确定ID,但按名称使用工作表Shapes集合对象
Set myShape = <SheetObject>.Shapes("<ShapeName>")
例如
Set myShape = ActiveSheet.Shapes("Rectangle 1")
答案 3 :(得分:0)
sName = ActivePresentation.Slides(k).Shapes(j).Name
其中k
是幻灯片编号和j
以及幻灯片上的形状编号。
您可以使用以下内容遍历每个页面形状:
k = 1
For j = 1 To ActivePresentation.Slides(k).Shapes.Count
Next j
克里斯