gpt4 book ai didi

vba - 通过 ID 或名称获取形状

转载 作者:行者123 更新时间:2023-12-02 08:23:44 52 4
gpt4 key购买 nike

如果您知道形状的 Id,有什么方法可以获取它吗?

例如:

Dim myshape As Shape
myshape.Id = 42
myshape = getShapeById(myshape.Id)

或者,我可以通过名称获取形状吗?

Dim myshape As Shape
myshape.Name = "Rectangle 42"
myshape = getShapeByName(myshape.Name)

最佳答案

通过 .Id 获取形状 .Namegetting 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

关于vba - 通过 ID 或名称获取形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5527073/

52 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com