To find a slide from the list of slides by name, one can use the .getByName()
method.
Option Explicit
Sub Main
Dim oSlideList as Object
Dim oSlide as Object
Dim oItem as Object
oSlideList = ThisComponent.getDrawPages()
oSlide = oSlideList.getByName("MyDesiredSlide")
oItem = oSlide.getByIndex(27)
End Sub
Rem This works!
I wanted to find a shape within a slide by name but unintuitively this didn’t work.
Option Explicit
Sub Main
Dim oSlideList as Object
Dim oSlide as Object
Dim oItem as Object
oSlideList = ThisComponent.getDrawPages()
oSlide = oSlideList.getByName("MyDesiredSlide")
oItem = oSlide.getByName("MyDesiredShape")
End Sub
Rem This does not work
BASIC runtime error.
Property or method not found: getByName.
I found FindObject()
which works but Pitonyak guide says it should not be used:
Option Explicit
Sub Main
Dim oSlideList as Object
Dim oSlide as Object
Dim oItem as Object
oSlideList = ThisComponent.getDrawPages()
oSlide = oSlideList.getByName("MyDesiredSlide")
oItem = FindObject("MyDesiredShape")
End Sub
Rem This works!
Do not use the functions FindObject and FindPropertyObject — they are poorly documented, buggy, and likely to be deprecated. I only mention the methods to be complete.
Is FindObject()
still “poorly documented” and “buggy” in 2023? Is it harmless in my use case? The reason I do not want to use getByIndex()
is that my slides are filled with shapes and finding objects by names is much easier when I have a good naming convention.