cross reference macro

I am trying to build a cross reference function for my macro in writer, something like this:


sub crossreference (file, namesection,reference)
   dim oDescriptor,ofound 
  oDescriptor = file.createSearchDescriptor()
  With oDescriptor
    .SearchString =  "banana"
  End With
  oFound = file.findFirst(oDescriptor)
  if isnull(ofound) then exit sub
  dim oField
  oField = file.createInstance("com.sun.star.text.textfield.GetReference")
  oField.ReferenceFieldPart = com.sun.star.text.ReferenceFieldPart.NUMBER
  oField.ReferenceFieldSource = 2
  oField.SourceName = "__RefNumPara__5813_2658656130"
	dim textcursor as object, oanchor, section as object
	textcursor = file.getText().createTextCursor()
	section = file.getTextSections.GetByName(namesection)
	oanchor = section.getAnchor()
	textcursor.gotoRange(oanchor, False)
	textcursor.collapseToEnd()
	file.getText().insertTextContent(textcursor, oField, false)
end sub

but the problem is i dont know how to get this part “__RefNumPara__5813_2658656130” the reference for the paragraph, probably an enumeration of some sort. Anyone knows how this works?

A hint: use preformatted text button (the one with 101010) for your source code, otherwise it becomes unreadable

Thanks for the hint Mike.