Get the form by ID or name

Is there a way to get the form if you know it Id?

For instance:

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

Or, otherwise, can I get a form Name?

Dim myshape As Shape
myshape.Name = "Rectangle 42"
myshape = getShapeByName(myshape.Name)
+3
source share
4 answers

To get Shapeon 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)
+1
source

Getting .Nameher form is .Idsomewhat more confusing than getting her .Idon.Name .

But here's how to do it:

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
+4
source

, Shapes

Set myShape = <SheetObject>.Shapes("<ShapeName>")

,

Set myShape = ActiveSheet.Shapes("Rectangle 1")
0
sName = ActivePresentation.Slides(k).Shapes(j).Name

where kis the number of the slide and jand the number of the form on this slide.

You can scroll through all forms of pages using something like:

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

Chris

0
source

Source: https://habr.com/ru/post/1695168/


All Articles