Impress macro is only partly functional when used in presentation as opposed to outside

I made an .odp file that contains two slides.

In Slide 1, there is a single circle that when clicked on moves to Slide 2. This circle uses a simple interaction and no macro.

In Slide 2, there is a square that when pressed hides the circle on Slide 1 then moves to Slide 1 so that by the time we are back at Slide 1 the circle is gone. It also uses an interaction but it runs a macro at mouse click. The interaction gui indicates that the name of the macro is vnd.sun.star.script:Standard.Module1.Hide?language=Basic&location=document.

Sub Hide

REM Define objects
Dim oDoc As Object
Dim oSlideList As Object
Dim oSlide As Object
Dim oSubject As Object
Dim oController As Object

REM oDoc refers to this presentation
oDoc = ThisComponent

REM oSlideList refers to the list of slides
oSlideList = oDoc.getDrawPages()

REM oSlide refers to the first slide
oSlide = oSlideList.getByIndex(0)

REM oSubject refers to the first object of the first slide
oSubject = oSlide.getByIndex(0)

REM Sets oSubject to be invisible
oSubject.Visible = False

REM Moves back to the first slide
oController = oDoc.getCurrentController()
oController.setCurrentPage(oSlide)

End Sub

I enabled macros then pressed F5 to enter presentation mode. Clicking on the circle in Slide 1 moved me to Slide 2 as expected. However clicking on the square in Slide 2 did not move me to Slide 1. I exited by pressing Esc, thinking the code failed. But I noticed that the circle in Slide 1 was no longer visible. So the macro did execute and hid the circle but did not move to the first slide.

After making the circle visible again, without entering presentation mode, in Slide 2, I right clicked on the square to bring the context menu. Then I clicked Execute Interaction. The circle disappeared and I was on Slide 1. So the code does fully work when I am not in presentation mode.

Finally after once again bringing back the circle I opened the dev menu, located my Hide function and pressed Run. The code proved to be functional yet again.

Am I using the wrong API to switch slides which is causing it to not work when in presentation? If so how should I change the oController section?


OK, what about

oController = oDoc.getPresentation().getController()
oController.gotoPreviousSlide()

or oController.gotoSlide(oSlide)?

1 Like

@JohnSUN Works like a charm! I didn’t know that presentation has its own controller. Thank you so much!

There are several. :slightly_smiling_face:

Msgbox Join(ThisComponent.getAvailableViewControllerNames(), Chr(10))
1 Like

Hello, I have the same problem in a certain Impress document, can you please share the file with the final solution for the circle and square? in .odp

testJumpSlide.odp (18.2 KB)

1 Like