"shape" throws and error

Hi All,

I am trying to save a chart.

From [Solved] Macro: Save Graphs as Images (many of them!) (View topic) • Apache OpenOffice Community Forum

Sub StoreDrawingOBjectAsImage
  shape = ThisComponent.getSheets().getByIndex(0).getDrawPage().getByIndex(0)
 
  Dim args(1) as new com.sun.star.beans.PropertyValue
  args(0).Name = "URL"
  args(0).Value = "file:///home/asuka/Downloads/foo.png"
  args(1).Name = "MimeType"
  args(1).Value = "image/png"
 
  gef = CreateUnoService("com.sun.star.drawing.GraphicExportFilter")
  gef.setSourceDocument(shape)
  gef.filter(args)
End Sub

“shape” throws “Basic Runtime Error 12”. What I am doing wrong, this time?

Many thanks,
-T

Which “shape”? you have it mentioned twice in your script.

By the way, it works for me (modulo changing the path to point to my place: args(0).Value = "file:///D:/Documents/foo.png").

Hopefully you do have a chart on your first sheet of the active spreadsheet.

It is on the second tab/sheet. What do I need to change?

shape = ThisComponent.getSheets().getByIndex(1).getDrawPage().getByIndex(0)

He forgot to declare “shape”

dim shape

Not “he”, but you (when using a very useful option explicit which requires each variable to be declared using DIM before using).

I am confused. Over on https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=67781#p301942
I do not see him declaring (with dim) the shape variable. Why do I need to declare and he does not?

As I have mentioned above, when you use option explicit in your module, you declare that any variable name must be declared before use, to avoid problems when you made a typo.

Books and sheets mentioned here might help you.