Ariel, I figured as much I was just hoping there was a single built in command like MS VBasic which has the method `.InsertCaption`. I will implement your suggestion and report back if it is a solution to my problem.
Thank you again for the advise I really do appreciate it. Kind Regards, Kurt -----Original Message----- From: Ariel Constenla-Haile <@googlemail.com> To: [email protected] Cc: Kurt Forrester <@googlemail.com> Subject: Re: [api-dev] Re: [dev] Basic insert caption openoffice Date: Fri, 3 Apr 2009 08:31:14 -0300 Hello Cor, Kurt On Friday 03 April 2009, 07:52, Cor Nouws wrote: > Sorry that I misunderstood your problem. > If I look at a caption of table in Writer, I see that > - paragraph style Table, which inherits from style Caption is applied; > - the line starts with the word "Table" > - has a field "Variable", type "Number range" and name "Table" > > So if you do those steps by code, it will be the caption. Cor is right, you have to do something like the following: Option Explicit Sub [Set a Title in all Doc's Tables] Dim oDoc as Object, oTables as Object, oTable as Object oDoc = ThisComponent oTables = oDoc.TextTables Dim n& For n = 0 to oTables.Count-1 oTable = oTables.getByIndex(n) SUB_Insert_Table_Title(oDoc, oTable) Next End Sub '****************************************************************** Sub SUB_Insert_Table_Title(oDoc as Object, Optional oTable) 'you can use the SUB directly on a table If IsMissing(oTable) then oDoc = ThisComponent oTable = oDoc.CurrentController.ViewCursor.TextTable End If If IsEmpty(oTable) or IsNull(oTable) then MsgBox "Twe need a table. Please put the cursor inside a cell!" Exit Sub End If Dim oParagraph as Object oParagraph = oDoc.createInstance("com.sun.star.text.Paragraph") oDoc.Text.insertTextContentBefore(oParagraph, oTable) oParagraph.ParaStyleName = "Table" oParagraph.String = "Table " Dim oCursorParagraph as Object oCursorParagraph = oDoc.Text.createTextCursorByRange(oParagraph) Dim oFieldMasters as Object Dim oMasterSetExpression as Object, oSetExpression as Object oFieldMasters = oDoc.TextFieldMasters oMasterSetExpression = oFieldMasters.getByName(_ "com.sun.star.text.FieldMaster.SetExpression.Table") oSetExpression = oDoc.createInstance (_ "com.sun.star.text.TextField.SetExpression") oSetExpression.Content = "Table+1" oSetExpression.SubType = com.sun.star.text.SetVariableType.SEQUENCE oSetExpression.Value = 1 oSetExpression.NumberFormat = FN_NumFormat(oDoc, "#.##0,00") oSetExpression.NumberingType = com.sun.star.style.NumberingType.ARABIC oSetExpression.attachTextFieldMaster( oMasterSetExpression ) oCursorParagraph.goToEndOfParagraph(false) oDoc.Text.insertTextContent ( oCursorParagraph , oSetExpression, false ) oDoc.Text.insertString ( oCursorParagraph , ": " , false ) oDoc.TextFields.refresh End Sub Function FN_NumFormat(oDoc as Object, sFormatCode as String) as Long Dim oNumberFormats, lFormat& Dim aLocale as New com.sun.star.lang.Locale oNumberFormats = oDoc.NumberFormats lFormat = oNumberFormats.queryKey(sFormatCode, aLocale, FALSE) If lFormat = -1 then lFormat = oNumberFormats.addNew(sFormatCode, aLocale) end if FN_NumFormat = lFormat End Function Regards
