Using Macros

From NeoWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 22:12, 22 December 2007 (edit)
Lorinda (Talk | contribs)
(Documentation/Support for Macros - reorganize this section; add some links)
← Previous diff
Revision as of 13:25, 25 April 2008 (edit) (undo)
Lorinda (Talk | contribs)
(Saving Code as a Macro - add instructions for creating new libraries and modules, other improvements.)
Next diff →
Line 13: Line 13:
Sometimes you may find code provided in a forum or in a text document that you want to add as a macro. To do so, follow these steps: Sometimes you may find code provided in a forum or in a text document that you want to add as a macro. To do so, follow these steps:
-*Under the {{menu|Tools}} choose {{menu|Macros}}, then {{menu|Organise Macros}}, and finally {{menu|NeoOffice Basic...}} +#Under the {{menu|Tools}} choose {{menu|Macros}}, then {{menu|Organise Macros}}, and finally {{menu|NeoOffice Basic...}}
-*Note that if the code is written in something other than NeoOffice/OpenOffice.org Basic, you need to choose the corresponding language at this point.+#:Note that if the code is written in something other than NeoOffice/OpenOffice.org Basic, you need to choose the corresponding language at this point.
-*Choose the Library and Module where you want the Macro to be stored in the left panel+#If necessary, click on the disclosure triangle next to {{prefName|My Macros}} to show the items stored there.
-**e.g. in My Macros-Standard-Module1 (it highights this by default)+#*If the Macro is only to be used in the current document, and/or if you plan to send the document to another user, you should click on the disclosure triangle next to the icon for the document in which you want to store the macro.
-*Make sure that "Main" is highlighted in the right panel+#*It is not possible to add macros the NeoOffice Macros
-*click on {{menu|Edit}}.+#Click on the discolosure triangle next to the Library where you want to store the macro.
-*Paste the code in anywhere below the Main/End Sub lines - making sure you don't paste in the middle of any other macros you saved; a couple of lines after Main's End Sub line is an obvious choice. +#:Note: while the {{prefName|Standard}} Library is selected by default, it storing Macros in the Standard library runs the risk of having those Macros deleted in certain circumstancs. Thus it is recommended to store all your macros in libraries you create and name. To create a new Library:
-*Click {{menu|Save}}+##Click on the {{Button|Organizer}} button
 +##In the {{Window|NeoOffice Basic Macro Organizer}} window, click on the {{Section|Libraries}} tab
 +##:''Note:'' If you are using another language (e.g. Python), the window will have a slightly different name.
 +##Make sure the {{Section|Location}} dropdown is set to {{prefName|My Macros & Dialogs}}
 +##:If you are storing the Macro in the document, however, choose the document name in the {{Section|Location}} dropdown.
 +##Click on the {{Button|New...}}
 +##Give the new Library a name
 +##Click {{Button|OK}}
 +##Click {{Button|Close}}
 +#Back in the {{Window|NeoOffice Basic Macros}}, click on the the Module you want to add the Macro code to. Modules are represented by scroll-like icons. If you wish to create a new Module, do the following:
 +##Make sure the Library you want to add the Module to is selected
 +##Click on the {{Button|Organizer}} button
 +##In the {{Window|NeoOffice Basic Macro Organizer}} window, click on the {{Section|Modules}} tab
 +##:''Note:'' If you are using another language (e.g. Python), the window will have a slightly different name.
 +##Click on the {{Button|New...}}
 +##Give the new Module a name
 +##Click {{Button|OK}}
 +##Click {{Button|Close}}
 +#Once your desired Library and Module are selected, make sure that "Main" is highlighted in the right panel
 +#click on {{menu|Edit}}.
 +#Paste the code in anywhere below the Main/End Sub lines - making sure you don't paste in the middle of any other macros you saved; a couple of lines after Main's End Sub line is an obvious choice.
 +#Click {{menu|Save}}
==Assigning a Shortcut Key to a Macro== ==Assigning a Shortcut Key to a Macro==

Revision as of 13:25, 25 April 2008

This article is not up to date, or it needs structural or stylistic changes to conform with the rest of this wiki.

Contents

Recording a Simple Macro

  1. Go to Tools, choose Macros and then Record Macro
  2. Perform the series of steps you want the macro to do for you automatically. (For example, apply a particular style)
  3. When you have finished all the steps, click on Stop recording
  4. In the window that appears, give the macro a name.
  5. Assign the macro to a Library and Module (See chapter 10 of the NeoOffice User Guide mentioned below for more information)
  6. Click Save when you have the settings the way you want

Saving Code as a Macro

Sometimes you may find code provided in a forum or in a text document that you want to add as a macro. To do so, follow these steps:

  1. Under the Tools choose Macros, then Organise Macros, and finally NeoOffice Basic...
    Note that if the code is written in something other than NeoOffice/OpenOffice.org Basic, you need to choose the corresponding language at this point.
  2. If necessary, click on the disclosure triangle next to My Macros to show the items stored there.
    • If the Macro is only to be used in the current document, and/or if you plan to send the document to another user, you should click on the disclosure triangle next to the icon for the document in which you want to store the macro.
    • It is not possible to add macros the NeoOffice Macros
  3. Click on the discolosure triangle next to the Library where you want to store the macro.
    Note: while the Standard Library is selected by default, it storing Macros in the Standard library runs the risk of having those Macros deleted in certain circumstancs. Thus it is recommended to store all your macros in libraries you create and name. To create a new Library:
    1. Click on the Organizer button
    2. In the NeoOffice Basic Macro Organizer window, click on the Libraries tab
      Note: If you are using another language (e.g. Python), the window will have a slightly different name.
    3. Make sure the Location dropdown is set to My Macros & Dialogs
      If you are storing the Macro in the document, however, choose the document name in the Location dropdown.
    4. Click on the New...
    5. Give the new Library a name
    6. Click OK
    7. Click Close
  4. Back in the NeoOffice Basic Macros, click on the the Module you want to add the Macro code to. Modules are represented by scroll-like icons. If you wish to create a new Module, do the following:
    1. Make sure the Library you want to add the Module to is selected
    2. Click on the Organizer button
    3. In the NeoOffice Basic Macro Organizer window, click on the Modules tab
      Note: If you are using another language (e.g. Python), the window will have a slightly different name.
    4. Click on the New...
    5. Give the new Module a name
    6. Click OK
    7. Click Close
  5. Once your desired Library and Module are selected, make sure that "Main" is highlighted in the right panel
  6. click on Edit.
  7. Paste the code in anywhere below the Main/End Sub lines - making sure you don't paste in the middle of any other macros you saved; a couple of lines after Main's End Sub line is an obvious choice.
  8. Click Save

Assigning a Shortcut Key to a Macro

  1. Go to Tools>Customize...
  2. Click on the Keyboard tab
  3. In the Category box, scroll down to "NeoOfficeMacros" and highlight it
  4. Burrow your way down through "user" and the library and module your macros are stored in. Eventually your new macros will be listed in the Function box
  5. Highlight one of those macros
  6. In the Shortcut Keys box select the key you want to assign to that macro
  7. Set the radio button to specify if the key assignment is for all of NeoOffice or only for Writer
  8. click Modify

Adding a Toolbar Button for a Macro

Creating a Button for a Macro

You can create a button which runs a macro in a Writer or a Calc document by using the followiing method:

  1. Go to the View menu, open the Toolbars sub-menu, and choose Form Controls.
  2. Click on the little triangle on the right top of the toolbar that appears to activate the design mode. Click on the Push button icon. The pointer changes into a cross.
  3. Draw the button as you wish. Control-click it, choose Control... in the context menu.
  4. Click on the General tab and give your button a title (label).
  5. Click on the Events tab. Click on the event, for example Mouse button pressed and click on the ... button to open the Assign action window.
  6. Click on the Macro... button.
  7. Choose your macro. Click on OK and again on OK, and then close the Properties: Button window.
  8. Quit the Design mode by clicking on the little triangle in the top right of the toolbar.

Documentation/Support for Macros

Print and E-books

Free

Chapter 10 of the NeoOffice User Guide discusses Basic and Macros. (The entire guide can be downloaded in pdf form from this link.)

The Getting Started with Macros Guide to OpenOffice.org can be downloaded with this link Just remember to use the command key where the OpenOffice guide says to use the control key.

Andrew Pitonyak has both a free downloadable document on OpenOffice Macros and a book that you can purchase.

Learn OpenOffice.org Spreadsheet Macro Programming: OOoBasic and Calc automation by Dr. Mark Alexander Bain (print or e-book for purchase). Look for the link to download a sample chapter (On working with Databases).

For Purchase

Andrew Pitonyak has both a free downloadable document on OpenOffice Macros and a book that you can purchase.

Forums and Wikis

The Open Office.org wiki has a section on BASIC.

The OpenOffice.org Community Forum has a forum on Macros.

The older OpenOffice.org Macros and API forum is a good source of information on Macros.

See especially this thread with an extensive list of internet and print resources on Macros.

Sources of Macros

OOoMacros.org has a library of macros available for download.
In the forums at trinity, yoxi provides the code for a macro to remove carriage returns.
Writer Tools A set of macros that appear as an additional menu in OpenOffice.org.

N.B. Currently Writer Tools do not appear to work in NeoOffice. See this thread in trinity. Should anyone be able to adapt them to work in NeoOffice, please post the solution(s) in the aforementioned trinity thread.

wr.Makros Macros for various components of OpenOffice.org.

Text of page is in German and English. These macros have not been tested on NeoOffice.


This article in other languages: Français
Personal tools