Calc Macros - Inserting and resizing image into active Sheet

I’m trying to create macro that will insert and resize image into active sheet
I found this code:
https://forum.openoffice.org/en/forum/viewtopic.php?t=81549

Folder = "C:\Users\fjcc\Desktop\"

imagen = "W21_0.TIF"
ImagenURL = convertToURL(Folder & imagen)
oImagen_obj = ThisComponent.createInstance("com.sun.star.drawing.GraphicObjectShape")

oImagen_obj.GraphicURL = ImagenURL
oSize = oImagen_obj.Size
oSize.Height = 3000
oSize.Width = 3000
oImagen_obj.Size = oSize
oPos = oImagen_obj.Position
oPos.X = 2000
oPos.Y = 3000
oImagen_obj.Position = oPos

oDP = ThisComponent.DrawPages.getByIndex(0)
oDP.add(oImagen_obj)

It’s almost perfect. Problem is it places this image always in first sheet.

oDP = ThisComponent.DrawPages.getByIndex(0)

I also tried something like ThisComponent.DrawPages.getByName(“sheetName”), but there is no such a function for this DrawPages thingy

I don’t know how to get index of active sheet

ThisComponent.CurrentController.ActiveSheet.RangeAddress.Sheet

2 Likes

It works, very fast reply, you are the best (ノ◕ヮ◕)ノ*:・゚✧

Or:

oDP = ThisComponent.CurrentController.ActiveSheet.DrawPage