REM ***** BASIC ***** Sub Main code = InputBox("Please enter the complete barcode as digits", "Postnetcodegenerator") InsertPostnetCode(code) End Sub sub InsertPostnetCode(barcode as string) ' barcode is the well-formed postnet-code in regular digits, including correction character ' (assume it is OK, no postprocessing necessary) ' example "123451234122" print barcode ' access the document model oDoc = ThisComponent ' get the Text service of the document oText = oDoc.getText() ' get the current cursor position in the GUI and create a text cursor from it oViewCursor = oDoc.getCurrentController().getViewCursor() oCursor = oText.createTextCursorByRange(oViewCursor.getStart()) ' create the AutoText service, chose group "Postnet" oAutoText = CreateUnoService("com.sun.star.text.AutoTextContainer") oPostnetGroup = oAutoText.getByName("Postnet") 'insert starting frame (tall bar) oPostnetEntry = oPostnetGroup.getByName("pf") oPostnetEntry.applyTo(oCursor) For i=1 To Len(barcode) id = Mid(barcode,i,1) ' choose autotext-Entry (Example: "p2": inserts barcode for number 2) and ' insert at current cursor-position oPostnetEntry = oPostnetGroup.getByName("p" & id) oPostnetEntry.applyTo(oCursor) Next i 'insert ending frame (tall bar) oPostnetEntry = oPostnetGroup.getByName("pf") oPostnetEntry.applyTo(oCursor) end sub