So I have a chart embedded in Writer that I created from a TextTable using Insert → Chart.
I find that I can update this chart by double clicking on the chart or right clicking on it and selecting Edit. (For some reason, I find that Tools → Update → Charts does not work for me, even if I record it as a Macro.)
What I want to do is update this embedded chart from a Macro. I’ve tried a number of ideas, but none of them work, or do not work properly. Assume that the chart is in object1. Here is a snippet of code I’ve tried:
Sub UpdateChart()
Dim xObj, oChart As Object
If ThisComponent.EmbeddedObjects.hasByName("Object1") Then
xObj = ThisComponent.EmbeddedObjects.getByName("Object1")
oChart = xObj.getEmbeddedObject()
oChart.update()
End If
End Sub
That fails to do anything. Another try was:
Sub UpdateChart()
Dim xObj, oChart As Object
If ThisComponent.EmbeddedObjects.hasByName("Object1") Then
xObj = ThisComponent.EmbeddedObjects.getByName("Object1")
XControl = xObj.getExtendedControlOverEmbeddedObject()
XControl.doVerb(0)
End If
End Sub
This effectively replicates the user right-clicking on the Chart and selecting Edit. So it puts the Chart in Edit mode and updates it as well. But – this leaves the Chart locked in Edit mode so far as Macro code goes and makes it hard to do anything else at that point.
My last try came about as a desperate attempt to just plug other numbers into the doVerb() to see if I could get it to do anything else. What I found was that I could update the chart in Edit mode, then escape the Edit mode by using doVerb(-3). But – that completely messed up the SideBar.
Sub UpdateChart()
Dim xObj, oChart As Object
If ThisComponent.EmbeddedObjects.hasByName("Object1") Then
xObj = ThisComponent.EmbeddedObjects.getByName("Object1")
XControl = xObj.getExtendedControlOverEmbeddedObject()
XControl.doVerb(0)
XControl.doVerb(-3)
End If
End Sub
Here’s what you see:
So the chart was updated, but the SiderBar is now empty, an undesirable side effect.
Does anyone know how a chart embedded in Writer can be updated from a Macro?