Other examples, just to learn OO Basic:
' Find the first paragraph in the document that begins with a capital letter.
Sub Find_Capitalized_Paragraph
Dim oDoc As Object
Dim oCursor As Object
Dim Proceed As Boolean
Dim CapTest As String
oDoc = ThisComponent
oCursor = oDoc.Text.createTextCursor()
oCursor.gotoStart(False)
Do
oCursor.goRight(1, True)
CapTest = oCursor.getString()
If CapTest <> "" And CapTest = UCase(CapTest) Then Goto TestPreviousEnd
oCursor.gotoNextParagraph(False)
Loop While CapTest <> ""
MsgBox("No results.")
Exit Sub
TestPreviousEnd:
MsgBox("Found result: """ & CapTest & """")
End Sub
Sub insert_in_cursor_position()
data = "Hello World with Basic"
REM Current document
doc = ThisComponent
REM Current selection always return a ranges, and get to end
text = doc.CurrentSelection.getByIndex(0).End
REM Write data
text.String = data
End Sub
Sub insert_image_in_current_position()
path_image = "/Users/hl/Dropbox/CT/Img/ct-blue-on-white.png"
doc = ThisComponent
text = doc.CurrentSelection.getByIndex(0).End
image = doc.createInstance("com.sun.star.text.GraphicObject")
image.GraphicURL = ConvertToURL(path_image)
image.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
image.Width = 2500
image.Height = 2500
cursor = doc.Text.createTextCursorByRange(text)
doc.Text.insertTextContent(cursor, image, False)
End Sub
alwayslockyourbike
' Find the first paragraph in the document that begins with a capital letter.
Sub Find_Capitalized_Paragraph
Dim oDoc As Object
Dim oCursor As Object
Dim Proceed As Boolean
Dim CapTest As String
oDoc = ThisComponent
oCursor = oDoc.Text.createTextCursor()
oCursor.gotoStart(False)
Do
oCursor.goRight(1, True)
CapTest = oCursor.getString()
If CapTest <> "" And CapTest = UCase(CapTest) Then Goto TestPreviousEnd
oCursor.gotoNextParagraph(False)
Loop While CapTest <> ""
MsgBox("No results.")
Exit Sub
TestPreviousEnd:
MsgBox("Found result: """ & CapTest & """")
End Sub