Is there some sort of way to tell how many words an article contains in Word 2007, without actually opening it? I need to do this programmatically, so simply opening it and looking at it can't do a computer any good! Perhaps there is some sort of API or something similar I could use?
perhaps the file size could give you a rough estimate. check out http://www.anycount.com/wordcounting_software/word_count/rtf_word_count.html and the google search i used http://www.google.com/search?hl=en&...word+count+in+microsoft+word+file&btnG=Search
I cant use a rough estimate, though. And plus, I'm using this for a program I am developing- so it can't use another paid program to function. And, I've used Google extensively before starting this topic.
It's ok, I created an algorithm that works almost as good. It just requires that the user input the article into my program for indexing. thanks for the help everyone.
Hi, I would use VBScript to do this. For the purpose of this exercise, this script will echo the Word Count to the screen, but it's a trivial task to pass the result as a variable to another part of your application. It's also fairly easy to dynamically assign the path/name of the Word doc, e.g. by having a user input box. VBScript can be wrapped up as a binary exe, by using something like AutoIt. Anyway here's my code. Copy and paste into txt file, and rename it with a .vbs extension. Change the location of the word doc in this line to the location of your document: wordPath = "C:\test.doc" Hope this helps! Steve Option Explicit ' "Option Explicit" helps us check for mistakes in the code! ' Declare The Word Application and the file path to the Word File Dim objWord Dim wordPath ' Declare the document we are currently reading data from Dim currentDocument ' Declare The number of Words in the current document Dim WordCount ' Locate the Word file wordPath = "C:\test.doc" ' Create an invisible instance of Microsoft Word Set objWord = CreateObject("Word.Application") ' Ignore any alerts objWord.DisplayAlerts = 0 ' Open the Word document as read-only objWord.Documents.Open wordPath, false, true ' Access the document Set currentDocument = objWord.Documents(1) ' Count The words in the document WordCount = currentDocument.Words.count ' Echo The word count to the screen WScript.Echo "There are " & WordCount & " words " & vbCRLF ' Close the word document currentDocument.Close ' Free the RAM used to store the document Set currentDocument = Nothing ' Quit Microsoft Word objWord.Quit Set objWord = Nothing Code (markup):
Excellent! Does the customer have to have Office or Word installed for this to work on their computers?
Well, yes, to use this particular script the customer will need Word installed. This is because the script calls MS Word here: Set objWord = CreateObject("Word.Application") However, with the advent of the open platform DOCX file extension, it's unlikely that your customer would need Word installed. DOCX - I believe, is XML based, and therefore, the task of retrieving a word count should be simple, because the document format is, in essence, nothing more than a bunch of metadata. I'm no expert in Word 2007, but I have a ton of experience in stuff like this, so please anyone - feel free to correct me in the latest inner workings of the MS Office Suite! Perhaps if you tell me what you're trying to achieve, I could help more? Feel free to PM me. Thanks, Steve
Use Macros and the script above, it should work for you. You would have to rip into their oh so proprietary code in order to get somewhere with this strategy. I can understand the use you will have for it, but you just need a proprietary software engineer or you will need to ask in the Microsoft forums/software engineer forums.
Well, I don't really need it anymore I'm just curious at this point. I found an algorithm that counts the words in a selected amount of text, but it was heavily flawed. It didn't count everything right, so I fixed it up with my own code and it works just as good as MS Word's word counter.