Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Recorded macro does not seem to include selection of columns that were selected while the macro was being recorded. If you record a macro of selecting cells then you can edit that recorded macro to select the two columns and then join the recorded macro with the hide columns macro.

Recording selection of two cells gives the following

sub Main

dim document   as object
dim dispatcher as object

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = "$L$1:$M$1"

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())

end sub

Then Edit to change "$L$1:$M$1" to "$L:$M". And Add the line to hide the columns selected as follows:

sub Main

dim document   as object
dim dispatcher as object

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = "$L:$M"

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())

dispatcher.executeDispatch(document, ".uno:HideColumn", "", 0, Array())

end sub

Recording macros is not always effective. Excel is better than LibreOffice for this but still the code generated is very inefficient and almost always requires manual edit to make the macro more general in its application. If you intend creating macros I'd recommend taking a look at Andrew Pitonyak's book, Open Office Macros Explained.

OOME_3_0.pdf

Also maybe refer to his site Book Site Link