通过 ID 或名称获取形状

发布于 2024-10-29 18:44:49 字数 312 浏览 3 评论 0原文

如果您知道形状的 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)

Is there any way to get a shape if you know its Id?

For example:

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

Or, alternatively, could I get the shape by Name?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

愿与i 2024-11-05 18:44:49

通过 .Id 获取形状 .Name通过 .Name 获取其 .Id

但它是这样实现的:

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

Getting a shape .Name by its .Id is somewhat more convoluted than getting its .Id by its .Name.

But here's how it's done:

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
岁月流歌 2024-11-05 18:44:49

要通过 Name 获取 Shape,您需要...:

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)

To get a Shape by Name, you do...:

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)
霞映澄塘 2024-11-05 18:44:49
sName = ActivePresentation.Slides(k).Shapes(j).Name

其中,k 是幻灯片编号,j 是该幻灯片上的形状编号。

您可以使用以下内容循环浏览每个页面形状:

k = 1
For j = 1 To ActivePresentation.Slides(k).Shapes.Count
Next j

Chris

sName = ActivePresentation.Slides(k).Shapes(j).Name

where k is the slide number and j and the shape number on that slide.

You can loop through each pages shapes with something like:

k = 1
For j = 1 To ActivePresentation.Slides(k).Shapes.Count
Next j

Chris

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文