Macro to move cursor from comments box to text

Hi. I wish to create a macro that inserts the same text in a comment box each time but which then returns me back to the text again afterwards.

I was able to do it in Word by creating two macros, the first to insert the text box and then the second to take me from the text box back to the text again. I can’t work out how to create the second macro though.

I know enough about macros to be able to do this, but anything more is at this point in time a bunch of gobbledegook. Can anyone help me?

Hi

The macro below inserts the comment at the current position of the cursor. The cursor remains positioned in the text so there is no need to “go back” to the text. You just have to adapt name & text of comment.

Sub LibOInsertComment

dim oCursor as object
dim oComment as object

oCursor = ThisComponent.CurrentController.getViewCursor()
oComment = thiscomponent.createInstance("com.sun.star.text.textfield.Annotation")
  
with oComment
	.Author = "Name Author Comment"
	.Content = "Text of comment"
	.DateTimeValue = CDateToUnoDateTime(now)
end with

oComment.attach(oCursor.start)

End Sub

Regards

Pierre-Yves, you are, quite simply, a legend.

Thank you so much. I really appreciate it. It will make my days a whole lot easier!