Replace an image using a macro

I am trying to replace an existing image (a external image) with another one but I can´t modify the image property Graphic.OriginURL

Ok @rodri , show the code (or better, a document with the code and an example image) - let’s try to figure out which of the lines of the macro needs to be corrected.

Sub macrorReplaceImage

Dim oDoct As Object, docProperties()
Dim sUrl, sImageFile, sImageURL As String
Dim oExistingGraph As Object
sUrl = convertToURL(“C:\Varios\Libtest\Doc1.odt”)
sImageFile = “C:\Varios\Libtest\italy.png”
sImageURL = convertToURL(sImageFile)

if fileExists(sUrl) then
oDoct = stardesktop.LoadComponentFromURL(sUrl, “_blank”,0, docProperties())
else
msgbox “Not found”
end if
oDP = oDoct.getGraphicObjects()

oExistingGraph = oDP.getbyIndex(0)
Print oExistingGraph.Graphic.OriginURL
oExistingGraph.Graphic.OriginURL = sImageURL

End Sub

Doc1.odt (9.4 KB)
italy

The image´s url is correctly read but it fails at the last line because OriginURL is read-only

Change last line in your macro:

oExistingGraph.GraphicURL = sImageURL

That solved it, thans