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

Creating a macro - Writing a Script - Using the API

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

Postby GuilhermeRafael » Thu Sep 08, 2016 9:16 pm

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   Expand viewCollapse view
    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
GuilhermeRafael
 
Posts: 2
Joined: Thu Sep 08, 2016 8:06 pm

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

Postby alessandrotristao » Sun Mar 10, 2019 9:16 pm

Did you find the code to insert the AutoText entry?
OpenOffice 3.1 on Windows 7
alessandrotristao
 
Posts: 1
Joined: Sun Mar 10, 2019 9:12 pm

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

Postby GuilhermeRafael » Tue Apr 02, 2019 12:13 am

Not yet, still using MSOffice instead
-GRV.
Windows 7 and 10
LibreOffice Portable 5.2.1
GuilhermeRafael
 
Posts: 2
Joined: Thu Sep 08, 2016 8:06 pm

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

Postby JeJe » Tue Apr 02, 2019 12:48 am

The macro recorder gives a result for this

Code: Select all   Expand viewCollapse view
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
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 629
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby JeJe » Tue Apr 02, 2019 12:54 am

looking at MRI, use getbyindex or getbyname and then applyto

Code: Select all   Expand viewCollapse view
oAutoText = createUnoService("com.sun.star.text.AutoTextContainer")
ovc = thiscomponent.currentcontroller.getviewcursor
oAutotext.getByIndex(0).getByIndex(0).applyto (ovc)

Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 629
Joined: Wed Mar 09, 2016 2:40 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 9 guests