LO WRITER BASIC: insert an image, put a drawing-text on top and jump to next page

Hello all,

I'm writing a macro to create a document entirely based on database-contents.
I have an image (page-sized) that should come on the first page, and then I should put the title on top of it and the jump to the next page. The part that follows (TOC + further contents of the document) is about finished and working but I have trouble with my title-page.

I tried to record the inserting of the image, then add text on top of it using the drawing toolbar, then set the properties of that text to centered (horizontal and vertical), size it to the text and then jump to the next page.

This resulted in this:

sub afbeelding_en_titel
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")

rem ----------------------------------------------------------------------
dim args2(3) as new com.sun.star.beans.PropertyValue
args2(0).Name = "FileName"
args2(0).Value = "file:///home/alain/Data/Indiegroup/Cover%20Offerte%20Site%20Builder.jpg"
args2(1).Name = "FilterName"
args2(1).Value = "<Alle indelingen>"
args2(2).Name = "AsLink"
args2(2).Value = false
args2(3).Name = "Style"
args2(3).Value = "Afbeeldingen"

dispatcher.executeDispatch(document, ".uno:InsertGraphic", "", 0, args2())

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:InsertDraw", "", 0, Array())

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:TransformDialog", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:TextAttributes", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:InsertLinebreak", "", 0, Array())

As you can see the recording didn't work after the inserting of the image and I find no documentation that accurately helps me figure it out the InsertDraw, TransformDialog and TextAttributes myself.

Could anybody help me on this one?
Any suggestion is welcome...

Thanks in advance,
Alain

Dag Alain ,
vlaming ja !

i see you use only the dispatcher you write your macro,
some actions can not been recorded, what not mean there is no dispatch action for it, there is a list for all dispatch actions <http://hermione.s41.xrea.com/pukiwiki/index.php?OOoBasic%2FGeneric%2Fcommands_2.2.1>
on this "hermione" website you find nearly all code you need
do some more Googling for examples and try to use the API based Basic Code.
so google for
Openoffice basixc API insert Image
Openoffice basixc API insert textframe
etc....

Groeten Fernand
(maandag ben ik terug op kantoor en daar heb ik ook alle code voorbeelden die je nodig hebt)

I believe that there are examples of inserting an image AndrewMacro.odt and probably also OOME (also available from my web site).

Does this at least get you started?

You stated that you were pulling data from a DB, how do you get your data from your database?

Hello Andrew,

Thanks for your reply. I'll take a look at your examples and will let you know if I succeeded.
Just for your info I include my complete macro so you can take a look at what I'm doing.
It's not completely working but most parts work, I can generate my complete document with TOC and save it.
The database is a Postgresql-database that I registered in OO-base.

REM ***** BASIC *****
dim sale_order_name as String
dim offerte as Object
dim DataBaseContext as Object
dim DataSource as Object
dim DBcon as Object
dim DBcon2 as Object
dim DBcon3 as Object
dim DBcon4 as Object
dim DBsql as Object
dim DBsql2 as Object
dim DBsql3 as Object
dim DBsql4 as Object
dim DBsql5 as Object
dim sale_order as Object
dim sale_order_id as Integer
Dim chapters as Object
Dim checklist as Object
Dim products as Object
Dim sale_order_type as Object
Dim sale_order_lines as Object
Dim Dummy()
Dim url as String
Dim Cursor as Object
Dim dispatcher as Object
Dim level as Integer
Dim mDoc as Object
Dim mCurs as Object
Dim oIndex as Object

Sub Main
     x=open_db()
     sale_order_name = inputbox("Geef offertenr aub","Offerte")
     DBsql=DBcon.createStatement()
     DBsql2=DBcon.createStatement()
     DBsql3=DBcon.createStatement()
     DBsql4=DBcon.createStatement()
     DBsql5=DBcon.createStatement()
     sale_order=DBsql.executeQuery("SELECT id, type_id, project_description, checklist_id FROM sale_order WHERE name='" + sale_order_name + "'"
     If Not Isnull(sale_order) Then
         While sale_order.next
             x=aanmaken_offerte()
             sale_order_id=sale_order.getInt(1)
             type_id=sale_order.getInt(2)
             chapters=DBsql2.executeQuery("SELECT title, image_url, description, level1_seq, chp_level, lines, checklist, products FROM sale_order_chapter WHERE " + _
                                         "type_id = " + type_id + " ORDER BY seq_nbr")
             sale_order_type=DBsql3.executeQuery("SELECT image_url FROM sale_order_type WHERE " + _
                                         "id = " + type_id)
             document = ThisComponent.CurrentController.Frame
             dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
             mDoc = ThisComponent
             mCurs = mDoc.currentController.getViewCursor()
             dim args4(3) as new com.sun.star.beans.PropertyValue
             While sale_order_type.next
                 args4(0).Name = "FileName"
                 args4(0).Value = sale_order_type.getString(1)
                 args4(1).Name = "FilterName"
                 args4(1).Value = "<Alle indelingen>"
                 args4(2).Name = "AsLink"
                 args4(2).Value = false
                 args4(3).Name = "Style"
                 args4(3).Value = "Afbeeldingen"
                 dispatcher.executeDispatch(document, ".uno:InsertGraphic", "", 0, args4())
                 dispatcher.executeDispatch(document, ".uno:SetAnchorToPara", "", 0, Array())
                 dispatcher.executeDispatch(document, ".uno:InsertLinebreak", "", 0, Array())
                 dispatcher.executeDispatch(document, ".uno:InsertPagebreak", "", 0, Array())
             Wend
             mCurs = mDoc.currentController.getViewCursor()
             oIndex = ThisComponent.CreateInstance("com.sun.star.text.ContentIndex")
             oIndex.CreateFromOutline = True
             ThisComponent.getText().insertTextContent(mCurs, oIndex, False)
             dim args1(0) as new com.sun.star.beans.PropertyValue
             dim args2(1) as new com.sun.star.beans.PropertyValue
             dim args3(2) as new com.sun.star.beans.PropertyValue
             level=0
             While chapters.next
                 if chapters.getInt(4) > level then
                     dispatcher.executeDispatch(document, ".uno:InsertPagebreak", "", 0, Array())
                 end if
                 level=chapters.getInt(4)
                 if chapters.getInt(5) = 1 then
                     args2(0).Name = "Template"
                     args2(0).Value = "Kop 1"
                     args2(1).Name = "Family"
                     args2(1).Value = 2
                     dispatcher.executeDispatch(document, ".uno:StyleApply", "", 0, args2())
                 else
                     args2(0).Name = "Template"
                     args2(0).Value = "Kop 3"
                     args2(1).Name = "Family"
                     args2(1).Value = 2
                     dispatcher.executeDispatch(document, ".uno:StyleApply", "", 0, args2())
                 end if
                 args1(0).Name = "Text"
                 args1(0).Value = chapters.getString(1)
                 dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
                 dispatcher.executeDispatch(document, ".uno:InsertPara", "", 0, Array())
                 args2(0).Name = "Template"
                 args2(0).Value = "Tekstblok"
                 args2(1).Name = "Family"
                 args2(1).Value = 2

                 if chapters.getBoolean(6) then
                     REM tabel invoegen
                     args4(0).Name = "TableName"
                     args4(0).Value = "Tabel1"
                     args4(1).Name = "Columns"
                     args4(1).Value = 3
                     args4(2).Name = "Rows"
                     args4(2).Value = 2
                     args4(3).Name = "Flags"
                     args4(3).Value = 11
                     dispatcher.executeDispatch(document, ".uno:InsertTable", "", 0, args4())
                     args1(0).Name = "Text"
                     args1(0).Value = "Product"
                     dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
                     dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
                     args1(0).Name = "Text"
                     args1(0).Value = "Hoev."
                     dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
                     dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
                     args1(0).Name = "Text"
                     args1(0).Value = "Prijs"
                     dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
                     sale_order_lines=DBsql4.executeQuery("SELECT name, product_uom_qty, " + _
                                         "(product_uom_qty * price_unit) AS amount, " + _
                                         "(SELECT seq_document from product_product where product_product.id = sale_order_line.product_id) AS seq " + _
                                         " FROM sale_order_line WHERE " + _
                                         "order_id = " + sale_order_id + " ORDER BY seq")

                     While sale_order_lines.next
                         naam=sale_order_lines.getString(1)
                         qty=sale_order_lines.getString(2)
                         amount=sale_order_lines.getString(3)
                         args1(0).Name = "Text"
                         args1(0).Value = naam
                         dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
                         dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
                         args1(0).Name = "Text"
                         args1(0).Value = qty
                         dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
                         dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
                         args1(0).Name = "Text"
                         args1(0).Value = amount
                         dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
                         dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
                     Wend
                     mCurs.gotoEnd(False)
                 end if

rem if chapters.getBoolean(7) then
rem REM tabel invoegen
rem args4(0).Name = "TableName"
rem args4(0).Value = "Tabel2"
rem args4(1).Name = "Columns"
rem args4(1).Value = 2
rem args4(2).Name = "Rows"
rem args4(2).Value = 2
rem args4(3).Name = "Flags"
rem args4(3).Value = 9
rem dispatcher.executeDispatch(document, ".uno:InsertTable", "", 0, args4())
rem checklist=DBsql4.executeQuery("SELECT question, answer, " + _
rem "(SELECT answer FROM survey_response_answer, survey_response_line " + _
rem "WHERE survey_response_answer.answer_id = survey_answer.id " + _
rem "AND survey_response_answer.response_id = survey_response_line.id " + _
rem "AND survey_response_line.question_id = survey_question.id " + _
rem "AND survey_response_line.response_id = survey_response.id) AS description " + _
rem "FROM survey_response, survey, survey_page, survey_question, survey_answer WHERE " + _
rem "survey_response.id = " + sale_order.getInt(4) + " AND " + _
rem "survey.id = survey_response.survey_id AND " + _
rem "survey_page.survey_id = survey.id AND " + _
rem "survey_question.page_id = survey_page.id AND " + _
rem "survey_answer.question_id = survey_question.id ORDER BY survey_question.sequence")
rem
rem while checklist.next
rem question=checklist.getString(1)
rem answer=checklist.getString(2)
rem description=checklist.getString(3)
rem args1(0).Name = "Text"
rem args1(0).Value = question
rem dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
rem args1(0).Name = "Text"
rem args1(0).Value = answer
rem dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
rem dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
rem args1(0).Name = "Text"
rem args1(0).Value = description
REM dispatcher.executeDispatch(document, ".uno:InsertPara", "", 0, Array())
rem dispatcher.executeDispatch(document, ".uno:InsertLinebreak", "", 0, Array())
rem dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
rem if not checklist.islast() then
rem dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
rem end if
rem Wend
rem mCurs.gotoEnd(False)
rem end if

                 if chapters.getBoolean(8) then
                     products=DBsql5.executeQuery("SELECT sale_order_line.name, product_template.description_sale, product_product.image, seq_document " + _
                                         "FROM sale_order_line, product_product, product_template WHERE " + _
                                         "sale_order_line.order_id = " + sale_order_id + " AND " + _
                                         "product_product.id = sale_order_line.product_id AND " + _
                                         "product_template.id = product_product.product_tmpl_id AND " +_
"product_template.description <> '' " + _
                                         "ORDER BY seq_document")

                     While products.next
                         naam=products.getString(1)
                         desc=products.getString(2)
                         args1(0).Name = "Text"
                         args1(0).Value = naam
                         args2(0).Name = "Template"
                         args2(0).Value = "Kop 3"
                         args2(1).Name = "Family"
                         args2(1).Value = 2
                         dispatcher.executeDispatch(document, ".uno:StyleApply", "", 0, args2())
                         dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
                         args1(0).Name = "Text"
                         args1(0).Value = desc
                         args2(0).Name = "Template"
                         args2(0).Value = "Tekstblok"
                         args2(1).Name = "Family"
                         args2(1).Value = 2
                         dispatcher.executeDispatch(document, ".uno:StyleApply", "", 0, args2())
                         dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
                     Wend
                 end if

                 if not isnull(chapters.getString(3)) then
                     args1(0).Name = "Text"
                     args1(0).Value = chapters.getString(3)
                     dispatcher.executeDispatch(document, ".uno:StyleApply", "", 0, args2())
                     dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
                     dispatcher.executeDispatch(document, ".uno:InsertPara", "", 0, Array())
rem dispatcher.executeDispatch(document, ".uno:InsertLinebreak", "", 0, Array())
                 end if
             Wend
             oIndex.update()
             x=opslaan_offerte(sale_order_name)
         Wend
     Else
         MsgBox "Offerte bestaat niet, probeer opnieuw aub"
     End If
     sale_order.Close
     DBsql.Close
     DBcon.Close
     DBcon.Dispose
End Sub

Sub open_db()
DataBaseContext=createUNOService("com.sun.star.sdb.DatabaseContext")
     DataSource=DatabaseContext.getByName("indiegroup")
     DBcon=DataSource.GetConnection("","")
End Sub

Sub aanmaken_offerte()
     url = "private:factory/swriter"
     offerte = StarDesktop.loadComponentFromURL(url, "_blank", 0, Dummy())
End Sub

Sub opslaan_offerte(naam)
     url = "file:///home/alain/Data/Indiegroup/" + naam + ".odt"
     offerte.storeAsUrl(url, Dummy())
     offerte.dispose
End Sub

Greetings,
Alain

Depending on what you really have in mind, some things may be easily doable still using the macro recorder. For example, I started with the cursor on

sub InsertSomeText(someText$)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem Add a new paragraph, which will use the same formatting as the current cursor location
dispatcher.executeDispatch(document, ".uno:InsertPara", "", 0, Array())

rem Move the cursor back to where it was.
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Count"
args2(0).Value = 1
args2(1).Name = "Select"
args2(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args2())

rem Set the font size (you said something about changing a size).
dim args3(2) as new com.sun.star.beans.PropertyValue
args3(0).Name = "FontHeight.Height"
args3(0).Value = 14
args3(1).Name = "FontHeight.Prop"
args3(1).Value = 100
args3(2).Name = "FontHeight.Diff"
args3(2).Value = 0

dispatcher.executeDispatch(document, ".uno:FontHeight", "", 0, args3())

rem Center the paragraph Horizontally
dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = "CenterPara"
args4(0).Value = true

dispatcher.executeDispatch(document, ".uno:CenterPara", "", 0, args4())

rem Insert the desired text here
dim args5(0) as new com.sun.star.beans.PropertyValue
args5(0).Name = "Text"
args5(0).Value = someText

dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args5())

REM Now, move the cursor back to the next line, which is where I expect you probably want to insert your image.
REM If you wanted this line to be centered horizontally, you need to do that CenterPara thing.
dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args2())

end sub

Now, what are you trying to set for a vertical alignment? The image? Are you able to do that directly from the GUI?

Hello Andrew,

Thanks for your help.
I tried this:

             document = ThisComponent.CurrentController.Frame
             dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
             mDoc = ThisComponent
             mCurs = mDoc.currentController.getViewCursor()
             mGraph = ThisComponent.CreateInstance("com.sun.star.text.GraphicObject")
             dim args4(3) as new com.sun.star.beans.PropertyValue
             While sale_order_type.next
                 rem Add a new paragraph, which will use the same formatting as the current cursor location
                 dispatcher.executeDispatch(document, ".uno:InsertPara", "", 0, Array())

                 rem Move the cursor back to where it was.
                 dim args2(1) as new com.sun.star.beans.PropertyValue
                 args2(0).Name = "Count"
                 args2(0).Value = 1
                 args2(1).Name = "Select"
                 args2(1).Value = false

                 dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args2())
                 args4(0).Name = "FileName"
                 args4(0).Value = sale_order_type.getString(1)
                 args4(1).Name = "FilterName"
                 args4(1).Value = "<Alle indelingen>"
                 args4(2).Name = "AsLink"
                 args4(2).Value = false
                 args4(3).Name = "Style"
                 args4(3).Value = "Afbeeldingen"
                 dispatcher.executeDispatch(document, ".uno:InsertGraphic", "", 0, args4())
                 dispatcher.executeDispatch(document, ".uno:SetAnchorToPara", "", 0, Array())
                 dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args2())
                 dispatcher.executeDispatch(document, ".uno:InsertLinebreak", "", 0, Array())
                 dispatcher.executeDispatch(document, ".uno:InsertPagebreak", "", 0, Array())
             Wend
             mCurs = mDoc.currentController.getViewCursor()
             oIndex = ThisComponent.CreateInstance("com.sun.star.text.ContentIndex")
             oIndex.CreateFromOutline = True
             ThisComponent.getText().insertTextContent(mCurs, oIndex, False)

The image is inserted correctly but I now get an error on the last line:
BASIC-runtime-fout.
Er is een uitzondering opgetreden
Type: com.sun.star.uno.RuntimeException
Message: text interface and cursor not related

What I see is that the image is still the selected object...
What am I missing?

Thanks for any help in advance...

Greetings,
Alain

Your observation that the image is still selected, is correct.
You can deselect an object (image) by pressing the Esc-button.
In other words I would add the following line before Wend:
dispatcher.executeDispatch(document, ".uno:Escape", "", 0, Array())

That will probably solve your problem, you might need to adjust
the exact location of the code line so that the image gets deselected
at the right time.

Regards,
Niklas Johansson

Alain Van Utterbeeck skrev 2013-08-19 10:44:

Hello Niklas,

thanks for your help, adding the escape line effectively solved my problem.

Do you know where possiblities such as the uno:Escape are documented, or where the possibilities can be found?

Greetings,
Alain

I had a document that listed many of them many years ago, but I never did bother to attempt to figure out how to tell what they all are. Even worse, the accepted parameters are not documented.

In other words, assume they are not documented.

OK, the moment I say that, I think, no, that can't be totally accurate so I looked at OOME to remind myself what was current last I checked.

http://wiki.openoffice.org/wiki/Framework/Article/OpenOffice.org_3.x_Commands

If you download the latest copy of OOME from my website,

http://www.pitonyak.org/OOME_3_0.odt

RUn the macro named Print_All_Commands (Listing 244)

Sub Print_All_Commands

' Create a new Calc document to hold the dispatch commands

Dim oDocAs Object

oDoc= StarDesktop.loadComponentFromURL("private:factory/scalc", "_default", 0, Array())

Dim oSheetsAs Object : oSheets= oDoc.getSheets()

'The UICommandDescription service provides access to the user interface commands that are

'part of OpenOffice.org modules, like Writer or Calc.

Dim oUICommandDescriptionAs Object

oUICommandDescription= CreateUnoService("com.sun.star.frame.UICommandDescription")

'Identify office modules and provide read access to the configuration of office modules.

Dim oModuleIdentifierAs Object

oModuleIdentifier= CreateUnoService("com.sun.star.frame.ModuleManager")

Dim oModuleUICommandDescriptionAs Object, aModules$(),aCommand

Dim aCommands$()

Dim n&, i&

' Get a list of module names such as "com.sun.star.presentation.PresentationDocument"

' Create a sheet for each module.

aModules= oModuleIdentifier.getElementNames()

For n= 0To UBound(aModules)

oModuleUICommandDescription= oUICommandDescription.getByName(aModules(n))

' Get the commands supported by this module.

ReDim aCommands$()

aCommands= oModuleUICommandDescription.getElementNames()

If n<= UBound(oSheets.getElementNames()) Then

oSheets.getByIndex(n).setName(aModules(n))

Else

oSheets.insertNewByName(aModules(n),n)

End If

oSheets.getCellByPosition(0, 0, n).getText().setString("Command")

oSheets.getCellByPosition(1, 0, n).getText().setString("Label")

oSheets.getCellByPosition(2, 0, n).getText().setString("Name")

oSheets.getCellByPosition(3, 0, n).getText().setString("Popup")

oSheets.getCellByPosition(4, 0, n).getText().setString("Property")

For i= 0To UBound(aCommands)

aCommand= oModuleUICommandDescription.getByName(aCommands(i))

Dim sLabel$, sName$, bPopupas Boolean, nProperty&, k%

For k= 0To UBound(aCommand)

If aCommand(k).Name = "Label"Then

sLabel= aCommand(k).Value

ElseIf aCommand(k).Name = "Name"Then

sName= aCommand(k).Value

ElseIf aCommand(k).Name = "Popup"Then

bPopup= aCommand(k).Value

ElseIf aCommand(k).Name = "Property"Then

nProperty= aCommand(k).Value

End If

Next

oSheets.getCellByPosition(0, i+1, n).getText().setString(aCommands(i))

oSheets.getCellByPosition(1, i+1, n).getText().setString(sLabel)

oSheets.getCellByPosition(2, i+1, n).getText().setString(sName)

If bPopupThen

oSheets.getCellByPosition(3, i+1, n).getText().setString("True")

Else

oSheets.getCellByPosition(3, i+1, n).getText().setString("False")

End If

oSheets.getCellByPosition(4, i+1, n).getText().setString(CStr(nProperty))

Next

Dim oColumnsas Object

oColumns= oSheets.getByIndex(n).getColumns()

Dim j%

For j= 0To 4

oColumns.getByIndex(j).setPropertyValue("OptimalWidth", True)

Next

Next

End Sub

The macro creates a Calc document and then a new sheet for each thing that supports dispatches (22 sheets) with the supported commands and a description.

Hi Alain

Well to be honest, I did a recording of myself pressing the Escape button in this case. :wink:

Most of the time I don't use the dispatch commands but instead use ThisComponent and go from there. That said, if you want to use the macro recorder and the dispatch commands I would say that you'll probably need to use a bit of trial and error to get things right. In some cases you might need to use keyboard shortcuts instead of the mouse to get better recordings (in this case the pressing the escape key to deselect the image). You can read about keyboard shortcuts and controlling LibreOffice with the keyboard in the built in help-files. And remember that if an object (image, frame etc) is selected commands don't always work the same as otherwise, just deselect it and you'll be good to go.

Andrews answer with the macro to list uno-commands in a Calc-document may definetily come in handy as well.

But if you really want to do more interesting stuff and get more control over your macros, consider getting familiar with a tool as XRay look trough Andrews documents search forums. Note that most macros written for OpenOffice are valid in LibreOffice so don't discard information about writing macros for OpenOffice.

Regards,
Niklas Johansson

Alain Van Utterbeeck skrev 2013-08-19 14:24:

I googled for a couple of hours to find this for a similar problem:
'probably this is due to the sometimes asynchroneous nature of the dispatch calls, try inserting a wait command'

So I changed the start of the code to:

                 if chapters.getBoolean(6) then
                     wait(120)
                     args4(0).Name = "TableName"
                     ...

and that solved my problem !

Thanks to all that helped me in getting my macro to work,

Greetings,
Alain

Hi :slight_smile:
WoooHooo!!  Congrats on solving this one and thanks for posting the answer back to the list!  That might well help other people in the future or at least make the answer a bit easier to find.

Thanks, congrats and regards from
Tom :slight_smile: