Ask Your Question

How would I make a hotkey for freezing and auto-width? [closed]

asked 2016-09-26 15:52:20 +0200

Kostiantyn Rybnikov gravatar image

Two very common operations which I do on opened document is to freeze its rows and columns, and then do automatic width to see full column names. But I struggled to find a simple way to add hotkeys for this action.

So, I would appreciate a lot if somebody could give me a straightforward way to do this. Thank you!

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-09-12 21:31:03.309882


Did you want a single hotkey to perform both actions or separate hot key for each? Macro can be recorded for the freeze row and columns but doesn't seem to record for column width. It can probably be done from macro written in BASIC, I'll take a look at this and try to provide example.

mark_t gravatar imagemark_t ( 2016-09-26 20:18:53 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2016-09-26 21:06:46 +0200

mark_t gravatar image

updated 2016-09-26 21:11:55 +0200

Example Code in Basic for a single macro to perform both functions

REM  *****  BASIC  *****

Option Explicit

Sub SetFreezeAndWidth

    ThisComponent.CurrentController.freezeAtPosition(1, 1)

    ThisComponent.CurrentSelection.Spreadsheet.Columns.OptimalWidth = True
End Sub

To place this in a module. From the menu "Tools", "Macros", "Organise Macros", "LibreOffice Basic..." then expand "My Macros", select "Standard" and click on "New". You can name the module or just keep the default and click "OK". Copy the above code into the new module replacing the existing Main sub.

Assign the macro to a hot key using the menu "Tools", "Customise...". On the "Keyboard" tab. At the top right select the "Calc" radio button. Select an un-used shortcut key combination. In "Category" expand "LibreOffice Macros", expand "user", expand "Standard", and select the module where you placed the code. In "Function" select the name of the sub "SetFreezeAndWidth". Then click on "Modify" to set the macro to the hot key selected. Click on OK to exit the dialog.

For more details on macros check the Andrew Pitonyak book

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-09-26 15:52:20 +0200

Seen: 58 times

Last updated: Sep 26 '16