Launching macros in Writer

Creating a macro - Writing a Script - Using the API

Launching macros in Writer

Postby corto-armitage » Fri Feb 22, 2019 11:04 am

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

Postby corto-armitage » Fri Feb 22, 2019 12:01 pm

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
corto-armitage
 
Posts: 20
Joined: Mon Jun 30, 2014 12:28 pm

Re: launching macros in Writer

Postby robleyd » Fri Feb 22, 2019 12:12 pm

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
Apache OpenOffice Developer Build 4.2.0 9820 - Slackware 14.2 - 64 bit
LibreOffice 6.0.7.3 - Slackware 14.2 - 64 bit
Apache OpenOffice 4.1.4 - Windows 7 Virtual machine
User avatar
robleyd
Moderator
 
Posts: 2731
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: Launching macros in Writer

Postby corto-armitage » Fri Feb 22, 2019 12:41 pm

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
corto-armitage
 
Posts: 20
Joined: Mon Jun 30, 2014 12:28 pm

Re: Launching macros in Writer

Postby RoryOF » Fri Feb 22, 2019 12:57 pm

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.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28939
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Launching macros in Writer

Postby RoryOF » Fri Feb 22, 2019 1:38 pm

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.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28939
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Launching macros in Writer

Postby JeJe » Fri Feb 22, 2019 1:51 pm

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   Expand viewCollapse view

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.
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 508
Joined: Wed Mar 09, 2016 2:40 pm

Re: Launching macros in Writer

Postby JeJe » Fri Feb 22, 2019 2:07 pm

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.
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 508
Joined: Wed Mar 09, 2016 2:40 pm

Re: Launching macros in Writer

Postby John_Ha » Fri Feb 22, 2019 8:38 pm

AOO 4.1.6, Windows 7 Home 64 bit

See the Writer Manual, the Writer FAQ, the Writer Tutorials and the Writer guide.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
 
Posts: 6617
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Launching macros in Writer

Postby corto-armitage » Mon Feb 25, 2019 1:36 pm

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   Expand viewCollapse view

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
corto-armitage
 
Posts: 20
Joined: Mon Jun 30, 2014 12:28 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: Lupp and 3 guests