[Solved] Macro to hide/unhide a Writer section

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Al Huneke
Posts: 11
Joined: Mon Mar 04, 2013 10:54 pm

[Solved] Macro to hide/unhide a Writer section

Post by Al Huneke »

Hi-

I'm pretty new to macros (and OO in general), but I'm getting there. I've figured out how to add custom operations to a toolbar by using the macro recorder and so far so good. But....I defined a section I want to hide and unhide with a toolbar button. When I record the operation Format/Sections..., pick my section name of interest and uncheck hide what gets recorded is:

Code: Select all

sub ShowRevHistory
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:EditRegion", "", 0, Array())
Not nearly enough. So it appears the recorder does not work in this case. Can anyone tell me why and/or offer some code to do what I need? I need to be able to select a specific section and check or uncheck the Hide checkbox.

Thanks!
Al
Last edited by Al Huneke on Tue Mar 05, 2013 5:19 am, edited 1 time in total.
Running OpenOffice 3.4.1 on both WinXP and Win7.
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Macro to hide/unhide a Writer section

Post by JohnV »

Code: Select all

Sub Hide_ShowSection
ts = ThisComponent.getTextSections
s1 = ts.getByName("Section1")
If s1.IsVisible then
  s1.IsVisible = false
 Else s1.IsVisible = true
EndIf  
End Sub
Al Huneke
Posts: 11
Joined: Mon Mar 04, 2013 10:54 pm

Re: [Solved]Macro to hide/unhide a Writer section

Post by Al Huneke »

Thanks for your quick reply John. Just what I needed.
Running OpenOffice 3.4.1 on both WinXP and Win7.
bluezeak
Posts: 12
Joined: Thu Oct 11, 2012 9:52 pm

Re: [Solved] Macro to hide/unhide a Writer section

Post by bluezeak »

For anyone interested in how to use a checkbox to implement the 'hide section' see link below.
(thanks so much for sharing the macro code!)

http://www.oooforum.org/forum/viewtopic.phtml?p=534295
OpenOffice 3.4 on Linux (Open Client Red Hat x64)
OpenOffice 3.4 on Windows 7
User avatar
DanielDG
Posts: 78
Joined: Wed Jun 25, 2014 10:44 am

Re: [Solved] Macro to hide/unhide a Writer section

Post by DanielDG »

Can this macro be used in a master document to hide sections? I have defined hidden section in the subdocuments of the master document, but I don't know how to hide them in the master document. I have to produce a PDF that has these sections excluded.
OpenOffice 4.1.0; Windows 7 Pro SP1 x64
Post Reply