Word and Page Count from MS Word lazarus / 21-General ---------------------------------------------------------------------- w click · 2021-09-20 15:03 I want to extract the word and page count from a Microsoft Word document.  In Delphi, I used MSWordAndPageCount(filename,words,pages) which was part of MSWordUnit.  No amount of searching reveals the Lazarus equivalent.  Can anyone advise, please? ---------------------------------------------------------------------- Jurassic Pork · 2021-09-20 15:16 hello, to do that only on windows ? Friendly, J.P ---------------------------------------------------------------------- Jurassic Pork · 2021-09-20 16:19 on Windows with msword installed you can  try this : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses ComObj, Variants;procedure TForm1.Button3Click(Sender: TObject);const mydoc = 'd:\temp\LazWord.docx';var msWord,sourceDoc : OleVariant;var nbPages,nbWords : integer;beginmsWord := CreateOleObject('Word.Application');// wdStatisticLines     1       Count of lines.// wdStatisticPages     2       Count of pages.// wdStatisticParagraphs        4       Count of paragraphs.// wdStatisticWords     0       Count of words.sourceDoc := msWord.Documents.Open(mydoc);nbPages := sourceDoc.ComputeStatistics(2);nbWords := sourceDoc.ComputeStatistics(0);ShowMessage('File ' + mydoc + #13#10 + 'nb Pages : ' + IntToStr(nbPages) +            #13#10 + 'nb Words : ' + IntToStr(nbWords));sourceDoc.Close;msWord.quit;end; ---------------------------------------------------------------------- w click · 2021-09-21 09:54 J.P., That works - many thanks.  Except that it reveals perhaps a few issues.  I was using something similar to simply open the document in Word and so I've three questions. 1. I was using a variant, not an OleVariant.  What's the difference? 2. I only used one and just called 'msWord.Documents.Open(mydoc);'.  So why assign it to sourceDoc? 3. I didn't 'sourceDoc.close' or 'msWord.quit' as I wanted to keep Word open.  Should I quit at least? And it's about three times slower! Cheers, David. ---------------------------------------------------------------------- Jurassic Pork · 2021-09-21 10:27 hello, Quote from: w click on September 21, 2021, 11:54:41 am1. I was using a variant, not an OleVariant.  What's the difference? 2. I only used one and just called 'msWord.Documents.Open(mydoc);'.  So why assign it to sourceDoc? 3. I didn't 'sourceDoc.close' or 'msWord.quit' as I wanted to keep Word open.  Should I quit at least? And it's about three times slower! 1- Property: The data type OleVariant is a variant data type that is used for OLE automation (automation of other programs). 2 - to have a document automation object. 3 - If you don't see MS Word windows, you don't know  if it is already opened  ---> if you want to see MsWord window add this : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i msWord.visible := True;   If msWord isn't visible don't forget to quit it when you close your application. Friendly, J.P ---------------------------------------------------------------------- w click · 2021-09-21 13:19 J.P., Grand, thank you. I knew the msword.visible bit, but much appreciated to know I'm on the right lines.  The program was just to fire up a Word document without faffing with finding the file, but I'm getting more ambitious. I think I should change Variant to OleVarient. And use 'msWord.quit'?  I'm guessing without it, it's endlessly filling memory up with OleVariants.  Or is sourcedoc.close needed too?  Basically, it fires up Word, I edit things and then quit from Word.  The program just sits in the background waiting for next time.  I'm not sure I can always remember to go back to the launching program to quit Word. Cheers, David.