Ask Your Question
0

How can I hide/show a shape of my spreadsheet using a macro?

asked 2017-04-19 16:07:22 +0100

Tarskovsky gravatar image

updated 2017-04-19 16:07:58 +0100

In VBA I was using this code:

Worksheets("Example").Shapes("TheShape").Visible = False

is there something which does the same on LibreOffice Calc?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2017-04-19 17:19:28 +0100

Ratslinger gravatar image

Shapes and pictures are located on the Drawpage. They are accessed through indexing. Here is an example to access your shape & turn on/off in a basic macro:

  oDrawPage = ThisComponent.getSheets().getByName("Sheet1").getDrawPage()
           'Get total # of objects on DrawPage'
  iCount = oDrawPage.Count
           'Cycle through objects'
  for x = 0 to iCount -1
    oImage = oDrawPage.getByIndex(x)
            'Check for wanted shape'
    If oImage.Name = "Shape1" Then
                 'Toggle visible or not      0 = NOT visible     1 = Visible'
            If oImage.Visible Then
                 oImage.Visible = 0
           Else
                oImage.Visible = 1
           End If
    End If
  Next x
edit flag offensive delete link more

Comments

Thank you very much!!! Can you link me to some good online documentation about libreoffice macros? I used to work on Excel, but now I will have to move all my code to LibreOffice. It looks like it's much powerful than Excel VBA, but a little more complicated.

Tarskovsky gravatar imageTarskovsky ( 2017-04-19 20:31:11 +0100 )edit

Unfortunately it can be much more complicated. But here are two sources which should easily get you started:

Open Office Macros Explained - PDF click here

LO documentation - click here

Ratslinger gravatar imageRatslinger ( 2017-04-19 20:51:00 +0100 )edit

Thanks man!

Tarskovsky gravatar imageTarskovsky ( 2017-04-19 21:36:43 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-04-19 16:07:22 +0100

Seen: 573 times

Last updated: Apr 19 '17