Launching macros in Writer

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
corto-armitage
Posts: 20
Joined: Mon Jun 30, 2014 12:28 pm

Launching macros in Writer

Post by corto-armitage »

Hello everyone,
in Word 2003 I had files I often accessed in a customizable Work menu (you just opened the file clicked on the menu clicked on Add and from then on it was on the menu). Alternatively I pressed Alt-F8 typed a three letter macro name and could launch a macro which opened the file (or did other things of course).

In Libre Writer I can't find any menu similar to the Work one

Also, I tried recording a macro that opens a file but when the file is opened it stops recording and the macro is not saved.

Even if I were to record a macro, opening a macro seems to require going through several submenus, which is time consuming to the point I might as well open the file directly. Isn't there a quicker way to do things? Do I need to associate the macro to a keyboard communication?
LibreOffice Version: 6.0.7.3 (x64)
Build ID: dc89aa7a9eabfd848af146d5086077aeed2ae4a5
CPU threads: 4; OS: Windows 10.0; UI render: default;
Locale: it-IT (it_IT); Calc: group
corto-armitage
Posts: 20
Joined: Mon Jun 30, 2014 12:28 pm

Re: launching macros in Writer

Post by corto-armitage »

In addition to what I wrote, I've just read online that Libre macros are unable of opening a window (which is depressing considering Word Perfect 5.1, the Dos-based Word-Processor I was using 30 years ago could handle this fine).

So, if that is indeed the case, I would rephrase the above question: in the absence of a macro, any quick way of accessing a file?
LibreOffice Version: 6.0.7.3 (x64)
Build ID: dc89aa7a9eabfd848af146d5086077aeed2ae4a5
CPU threads: 4; OS: Windows 10.0; UI render: default;
Locale: it-IT (it_IT); Calc: group
User avatar
robleyd
Moderator
Posts: 5055
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: launching macros in Writer

Post by robleyd »

If it isn't on the recently used list, then I don't know of a quicker method than File | Open in AOO. You could create shortcuts via your operating system; obviously that may become inconvenient with a large number of files.

There is an extension history manager which allows you to increase the number of recent file names stored; my experience with it has been less than desirable.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.1.2; SlackBuild for 24.2.1 by Eric Hameleers
corto-armitage
Posts: 20
Joined: Mon Jun 30, 2014 12:28 pm

Re: Launching macros in Writer

Post by corto-armitage »

Thx, David. That's disappointing news
LibreOffice Version: 6.0.7.3 (x64)
Build ID: dc89aa7a9eabfd848af146d5086077aeed2ae4a5
CPU threads: 4; OS: Windows 10.0; UI render: default;
Locale: it-IT (it_IT); Calc: group
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Launching macros in Writer

Post by RoryOF »

There are some useful macros at http://open-office.es including, if I remember correctly, a macro toolbar that permits speedy access to the installed macros. That site is in Spanish, so you may need to pass sentences through a translator.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Launching macros in Writer

Post by RoryOF »

If you can locate a copy of How_to_use_basic_macros.sxw (sxw is an outdated OO format, and can be converted to .odt by earlier OO versions, perhaps Oo 3.x(?)), this is a brief introduction to using macros in OO and includes instructions for linking a macro to a toolbar button.

It does not teach OO BASIC - it assumes you have a working knowledge of that; from memory its screenshots of the builtin macro organiser are from a very early version of OO, but they can be related easily to the current screens.

The master work on OO macros is still that of Andrew Pitonyak.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Launching macros in Writer

Post by JeJe »

This macro will open a file. Just change "C:\tmp\footnote test.odt" to the path of your file. It will work in LibreOffice

Code: Select all


Sub OpenFile()
dim oDoc,opth as string, args() as  new com.sun.star.beans.PropertyValue
  opth= "C:\tmp\footnote test.odt" 
  oDoc = StarDesktop.loadComponentFromURL(convertToURL(opth), "_blank", 0, Args())
End Sub
Edit: corrected to 'as new com.sun.star.beans.PropertyValue'
Last edited by JeJe on Fri Feb 22, 2019 5:27 pm, edited 1 time in total.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Launching macros in Writer

Post by JeJe »

If you go to Tools/macros/organise macros/LibreOffice Basic/ My Macros/standard module and put the macro there... then
using Tools/customize, you can assign a shortcut or a toolbar item or a menubar item to the macro.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
John_Ha
Volunteer
Posts: 9583
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Launching macros in Writer

Post by John_Ha »

LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
corto-armitage
Posts: 20
Joined: Mon Jun 30, 2014 12:28 pm

Re: Launching macros in Writer

Post by corto-armitage »

JeJe wrote:This macro will open a file. Just change "C:\tmp\footnote test.odt" to the path of your file. It will work in LibreOffice

Code: Select all


Sub OpenFile()
dim oDoc,opth as string, args() as  new com.sun.star.beans.PropertyValue
  opth= "C:\tmp\footnote test.odt" 
  oDoc = StarDesktop.loadComponentFromURL(convertToURL(opth), "_blank", 0, Args())
End Sub
Thanks a lot everyone, will try and let you know

Edit: corrected to 'as new com.sun.star.beans.PropertyValue'
LibreOffice Version: 6.0.7.3 (x64)
Build ID: dc89aa7a9eabfd848af146d5086077aeed2ae4a5
CPU threads: 4; OS: Windows 10.0; UI render: default;
Locale: it-IT (it_IT); Calc: group
Post Reply