Add index of pages to a textframe in Draw
Posted: Wed Mar 04, 2026 11:09 pm
Add index of pages to a textframe in Draw
Select the chosen frame (formatted with the font/columns etc desired). Click on the border of the frame NOT the text in the frame, and run the first sub.
Edit: fixes thanks to cwolan, OpenOffice uses "Slide" as a default name instead of "Page" and made modified = true after running.
Select the chosen frame (formatted with the font/columns etc desired). Click on the border of the frame NOT the text in the frame, and run the first sub.
Edit: fixes thanks to cwolan, OpenOffice uses "Slide" as a default name instead of "Page" and made modified = true after running.
Code: Select all
Sub AddIndexToTextFrame() 'Select the frame by clicking on the border - NOT the text in the frame
dim pagename as string,oDoc,oDrawPages,otext,i as long,url,representation
oDoc = ThisComponent
oDrawPages = odoc.drawpages
otext = thiscomponent.currentselection.getbyindex(0).gettext
otext.string = ""
For i = 0 To oDrawPages.getCount() - 1
pageName = oDrawPages.getByIndex(i).Name
'If pageName = "" or 'NOT SURE IF THIS EVER OCCURS
if pagename = ("page" & i+1) then pageName = oDrawPages.getByIndex(i).LinkDisplayName
url = "#" & pagename
representation = pagename
InsertHyperlinkInTextShape2(odoc,otext,url,representation)
oText.insertString(oText.getEnd(), Chr(13), False)
Next i
thiscomponent.modified = true
msgbox "Done"
End Sub
sub InsertHyperlinkInTextShape2(odoc,oText,url,representation)
dim field
field = odoc.createInstance("com.sun.star.text.textfield.URL")
with field
.url = url
.Representation =representation
.format = 2
.TargetFrame ="_self"
end with
oText.insertTextContent(otext.getend, field, False)
end sub