Page 1 of 1

Word count for Impress document

Posted: Wed Jul 15, 2026 10:58 pm
by JeJe
creates a writer document and inserts the text from all shapes in the current Impress document as a simple way to get a word count - which isn't natively available in Impress

Edit: tested on LibreOffice only

Code: Select all


'creates a writer document and inserts the text from all shapes in the current Impress document 
Sub countImpressWords 

dim odoc,odoc2,opages,i,tc,j,oshape, oSourcePage
odoc =thiscomponent     
oPages = odoc.getDrawPages()
    
    oDesk = CreateUnoService("com.sun.star.frame.Desktop")
    oDoc2 = oDesk.loadComponentFromURL("private:factory/swriter", "_blank", 0, array())
tc = odoc2.text.createtextcursorbyrange(odoc2.text.getstart)
   on error resume next
    For i = 0 To oPages.getCount() - 1
   
   oSourcePage=odoc.drawpages(i)
if oSourcePage.count>0 then
    for j = 0 to oSourcePage.count -1
    oshape = oSourcePage.getbyindex(j)
with tc
.string = oshape.string
.collapsetoend
.string= chr(13)
.collapsetoend
end with
Next 
end if
next

end sub