[Tutorial] Binding a macro: Shortcut key, menu or toolbar

Home made tutorials, by users, for users
Forum rules
No question in this forum please
For any question related to a topic, create a new thread in the relevant section.

[Tutorial] Binding a macro: Shortcut key, menu or toolbar

Postby bobban » Fri Dec 05, 2008 8:27 am

This tutorial assumes you now have a macro that you want to bind to a Shortcut key, menu or toolbar. If you are trying to import a macro then see the tutorial on how to install a code snippet, then come back here when you are ready to bind it. Or, you might want to record a macro first, then bind that.

All the following steps use a macro I recorded called 'PasteSpecialMacro' (the steps to record this macro are at the bottom of this post). I have this macro stored within a module called 'MyRecordedMacrosModule'. This module exists within the 'Standard' library.


1. Binding to a Shortcut key

1) Tools->Customize->Keyboard
2) first pick your key combination in the 'Shortcut keys' pane, ensuring nothing else is bound to it, or you are willing to overwrite it if there is.
3) then in the 'Category' pane select: OpenOffice.org Macros->user->Standard->MyRecordedMacrosModule
4) then in the 'Function' pane select: PasteSpecialMacro
4) now press 'Modify' and you should have your Shortcut key bound to the PasteSpecialMacro (the full path of the macro will be displayed next to the Shortcut key).

BindMacroToKey.png

Note: It is possible to make the binding specific to Calc, or global to all OOo components using the radio buttons above the Modify button. If a Shortcut key has a global setting, a Calc specific setting will override that while using Calc.

2. Binding to a Menu

This process is similar to the Shortcut key. One nice thing about menus is that they allow you to create your own sub-menu. I will do that here, by creating a sub-menu called 'My Own Macros', within the already existing 'Tools' menu (obviously that is overkill since we only have one macro but may be handy if you acquire more).

1) Tools->Customize->Menus
2) From the 'Menus' drop down box select 'Tools' (all the entries with a vertical line then a second word indicate an existing sub-menu ie. 'Tools | Language')
3) Select the position where you want your sub-menu to be in the 'Entries' box (you can move up or down later with the arrows on right if you want).
4) Now select: Modify->Add Submenu... and name it 'My Own Macros'.
5) back to the 'Menu' drop down box and select 'Tools | My Own Macros', and you will see the entries box is blank.
6) Select 'Add'
7) then in the Category pane: OpenOffice.org Macros->My Macros->Standard->MyRecordedMacrosModule
8) then in the 'Commands' pane select: PasteSpecialMacro, press 'Add', then 'Close' and 'OK' on the Customize dialog and you are done.

BindMenu.png



3. Binding to a Toolbar
Almost identical to binding to a menu. As of OOo v3.0.0 it is not possible to create a sub-menu within a toolbar even though some existing toolbar items have sub-menus (Modify->'Begin a group' command is simply to add a separator).

1) Tools->Customize->Toolbars
2) From the 'Toolbars' drop down box select the toolbar you want to add this command to (you can create a new one if you want).
3) Select the position where you want your macro to be in the 'Commands' box (you can move up or down later with the arrows on right if you want).
4) Select 'Add'
7) then in the Category pane: OpenOffice.org Macros->My Macros->Standard->MyRecordedMacrosModule
8) then in the 'Commands' pane select: PasteSpecialMacro, press 'Add', then 'Close' and 'OK' on the Customize dialog and you are done.

Here is a picture showing the results from all three steps being done (the Shortcut key binding is displayed on a menu item).
Macro assigned.png



Recording a macro for this tutorial
By no means a full tutorial on this subject. Just how to record the 'PasteSpecialMacro' used in the above steps. The goal of this macro is to record a version of Paste Special that you might use regularly (ie. paste only text etc).

1) Click your source cell and copy
2) then select any single cell as a destination.
3) Now start recording: Tools->Macros->Record Macro(F7)
4) do the paste special in the cell you selected with your preferred options
5) Now stop recording
6) You want to save the macro within the 'Standard' library (one of the root folders you will see under 'MyMacros'). When that is selected then press 'new module', and give it a meaningful name such as 'MyRecordedMacrosModule'.
7) Once that is done, this module will be selected and you now must name your macro (ie. 'PasteSpecialMacro') using the text box in top left corner (default name will be Main).
8) bind to Shortcut key, menu or toolbar as above.

Note: Do not select any new cells while recording or that action will get recorded too which you don't want, since you want just a paste special. You could do a few of these if you wanted for a few different paste special options.

Please contact me if you have any corrections or suggestions.
Last edited by bobban on Wed Dec 10, 2008 5:42 pm, edited 3 times in total.
OOo 3.1.1 on Ms Windows XP
User avatar
bobban
Volunteer
 
Posts: 535
Joined: Sat Nov 01, 2008 3:12 pm
Location: Australia

Re: [Tutorial] Binding a macro: Shortcut key, menu or toolbar

Postby bobban » Fri Dec 05, 2008 8:35 am

Change log reserved post.
OOo 3.1.1 on Ms Windows XP
User avatar
bobban
Volunteer
 
Posts: 535
Joined: Sat Nov 01, 2008 3:12 pm
Location: Australia

Re: [Tutorial] Binding a macro: Shortcut key, menu or toolba

Postby Tommy » Sat Jul 31, 2010 8:03 pm

nice tutorial. :super:
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
Tommy
 
Posts: 252
Joined: Sun Dec 23, 2007 2:44 pm


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests