I'm trying to use Basic macros to make a shape change its color when clicked during presentation mode. My goal is to create versatile code that works on any slide, regardless of the number of shapes.
I have a code that works (see below) when I use the "Execute interaction..." option. However, in presentation mode, clicking on the shape is possible, but it does not change the color. I've found that specific coding is needed for presentation mode to work correctly. Unfortunately, I haven't been successful in making it work.
The code that works with "Execute interaction...":
Sub ChangeColorToRed()
Dim oDoc As Object
Dim Page As Object
Dim oSelection As Object
Dim SelectedShape As Object
oDoc = ThisComponent
Page = oDoc.DrawPages(0)
oSelection = oDoc.getCurrentSelection()
If oSelection.getCount() > 0 Then
SelectedShape = oSelection.getByIndex(0)
SelectedShape.FillColor = RGB(0, 200, 0) ' Cor desejada, por exemplo, verde (0, 200, 0)
End If
End Sub
I'm using LibreOffice 7.6.4.1 60 with Manjaro.
DISTRIB_ID="ManjaroLinux"
DISTRIB_RELEASE="23.1.3"
DISTRIB_CODENAME="Vulcan"
DISTRIB_DESCRIPTION="Manjaro Linux"
You are unnecessarily complicating the task. Instead of running a macro through Interaction, use the adjacent Animation context menu item.
Select the object for which you are going to change the color, click the Add button. In the Category field, select Emphasis: Select an emphasis effect from the list of effects. Find "Basic-Change Fill Color" in the list of Effects. Reduce the time Duration, for example to 0.01 seconds, select a suitable green color.
Run a Slide Show of your presentation and make sure everything works as intended.
By the way, it is unimaginably difficult to perform this task using a macro - the presentation don't say to the macro from which Shape it was launched. And Artificial Intelligence will not cope with such a task either.