In an office application, a macro is a predefined set of instructions that can be saved and executed when the user wants it to. The uses are varied and isn't limited to word processing. For example, you can use a macro in a spreadsheet to highlight a certain set of cells and do something with them, ie. formatting, changing values etc. Usually you can record macro's graphically and the application will create a list of macro commands from the things you do. Or if you have coding experience you can write your own, although macros in MS Office would be different to OpenOffice etc.
As per your example, yes it is possible to use a macro for that, but the uses aren't limited to that, Because of this however, there have been certain security issues with unknown documents having malicious macros recorded in them, so be careful about running any from an unknown source.
To record your own macro, in MS Office its usually tools>macros>record macro. however there are varying degrees of success.