Code to insert AutoText at given point in document w/ Macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
GuilhermeRafael
Posts: 2
Joined: Thu Sep 08, 2016 8:06 pm

Code to insert AutoText at given point in document w/ Macro

Post by GuilhermeRafael »

I'm trying to translate to OpenOffice Basic the macros I have in MSOffice, which I use to automate some repetitive tasks. For that, I have designed a form with several check boxes, which will position in given order in the document all the associated AutoText entries. The code in MS VBA looks like this:

Code: Select all

    If Accident = True Then
     NormalTemplate.AutoTextEntries("Accident merit").Insert _
     Where:=ActiveDocument.Bookmarks("merit").Range, RichText:=True
     NormalTemplate.AutoTextEntries("medical expert's fees").Insert _
     Where:=ActiveDocument.Bookmarks("expertFees").Range, RichText:=True
    End If
I have searched all around but haven't yet found out how to do so in LibreOffice. I know it has something to do with the service com.sun.star.text.XAutoTextEntry or XText, but I haven't figured out the actual code that will insert the AutoText in the document. Ideally, I'd like to replace some markup text such as "<merit>" with the AutoText entry instead of using Bookmarks as I did in MS VBA, because otherwise I'd also have to delete all Bookmarks afterwards, and that's something else I haven't figured out how to do as well...
-GRV.
Windows 7 and 10
LibreOffice Portable 5.2.1
alessandrotristao
Posts: 1
Joined: Sun Mar 10, 2019 9:12 pm

Re: Code to insert AutoText at given point in document w/ Ma

Post by alessandrotristao »

Did you find the code to insert the AutoText entry?
OpenOffice 3.1 on Windows 7
GuilhermeRafael
Posts: 2
Joined: Thu Sep 08, 2016 8:06 pm

Re: Code to insert AutoText at given point in document w/ Ma

Post by GuilhermeRafael »

Not yet, still using MSOffice instead
-GRV.
Windows 7 and 10
LibreOffice Portable 5.2.1
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Code to insert AutoText at given point in document w/ Ma

Post by JeJe »

The macro recorder gives a result for this

Code: Select all

rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args9(1) as new com.sun.star.beans.PropertyValue
args9(0).Name = "Group"
args9(0).Value = "crdbus50"
args9(1).Name = "ShortName"
args9(1).Value = "ELE2"

dispatcher.executeDispatch(document, ".uno:InsertGlossary", "", 0, args9())

This thread shows how to access the entries

viewtopic.php?f=45&t=27179
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: Code to insert AutoText at given point in document w/ Ma

Post by JeJe »

looking at MRI, use getbyindex or getbyname and then applyto

Code: Select all

oAutoText = createUnoService("com.sun.star.text.AutoTextContainer")
ovc = thiscomponent.currentcontroller.getviewcursor
oAutotext.getByIndex(0).getByIndex(0).applyto (ovc)

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply