You're probably looking for automation, so these are the commands you're after (click them to jump the wiki article):
For that task you'll likely be better served with something like AutoHotKey (probably the first result when you google that name).
On the other hand, OpenOffice (now LibreOffice) has a BASIC interpreter built in (a version of Visual Basic for Applications) and automation can probably work best if done from inside out in that case, instead of using an external program to do it.