Word count for Impress document

Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
Post Reply
JeJe
Volunteer
Posts: 3134
Joined: Wed Mar 09, 2016 2:40 pm

Word count for Impress document

Post 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
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply