Question about Hide/Show Macro

Hi,

I have a macro which hides a section of my spreadsheet. I’ve attached this macro to a custom toolbar so that with a press of the toolbar button it automatically closes (hide) some cells. However; my question is whether it is possible to have the cells open (show) again with the same button (macro)? Could someone answer whether this is possible? (Basically an if shown then hide ; if hidden then show)

Here is my current macro:

Sub HideToDo

dim oDoc as Object
dim oDisp as Object
dim oSheet as Object

oDoc = ThisComponent.CurrentController.Frame
oDisp = createUnoService(“com.sun.star.frame.DispatchHelper”)
oSheet = ThisComponent.CurrentController.ActiveSheet

dim pArgs(0) as new com.sun.star.beans.PropertyValue
pArgs(0).Name = “ToPoint”
pArgs(0).Value = “$E$1”
oDisp.executeDispatch(oDoc, “.uno:GoToCell”, “”, 0, pArgs())
oDisp.executeDispatch(oDoc, “.uno:HideColumn”, “”, 0, Array())

End Sub

Thanks so much!

Instead coding copy and pasting code you should just select Column E…and do →Data→Group and Outline→Group and have a look at the tiny ***+|-***button directly over Column E

def toggle_column_E(*_):
    doc = XSCRIPTCONTEXT.getDocument()
    sheet = doc.CurrentController.ActiveSheet
    E.IsVisible = not (E:=sheet.Columns.E).IsVisible

thats python…may be YOU NEED BASIC!

sub toggle_column_E
    doc = thisComponent
    sheet = doc.CurrentController.ActiveSheet
    column = sheet.Columns(4)
    column.IsVisible = not column.IsVisible
end sub

Is this something i can just paste in my existing code?
(i’m quite a noob at this stuff, I just copy / paste what I find online)

the basic-code you can just copy&paste below your existing sub… remove the existing sub … and assign the button to the new sub.
I you will try to work with the python-code, I should first download apso.oxt from this site and install it, it helps especially for organizing Python.