Word Functionality

Discussion in 'Bing' started by zac439, Jun 17, 2007.

  1. #1
    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?
     
    zac439, Jun 17, 2007 IP
  2. lilylidou

    lilylidou Peon

    Messages:
    281
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think you can use macro.
     
    lilylidou, Jun 20, 2007 IP
  3. zac439

    zac439 Notable Member

    Messages:
    3,074
    Likes Received:
    214
    Best Answers:
    0
    Trophy Points:
    260
    #3
    Any idea on how to do this? Wouldn't I need to open Word to use a macro?
     
    zac439, Jun 20, 2007 IP
  4. RuDeDoGg

    RuDeDoGg Well-Known Member

    Messages:
    178
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    110
    #4
    RuDeDoGg, Jun 26, 2007 IP
  5. zac439

    zac439 Notable Member

    Messages:
    3,074
    Likes Received:
    214
    Best Answers:
    0
    Trophy Points:
    260
    #5
    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.
     
    zac439, Jun 26, 2007 IP
  6. Boris69

    Boris69 Guest

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i wanted to say macro, but in this case dunno!!
     
    Boris69, Jun 26, 2007 IP
  7. zac439

    zac439 Notable Member

    Messages:
    3,074
    Likes Received:
    214
    Best Answers:
    0
    Trophy Points:
    260
    #7
    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.
     
    zac439, Jun 26, 2007 IP
  8. smarketing

    smarketing Active Member

    Messages:
    117
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #8
    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):
     
    smarketing, Jul 1, 2007 IP
  9. zac439

    zac439 Notable Member

    Messages:
    3,074
    Likes Received:
    214
    Best Answers:
    0
    Trophy Points:
    260
    #9
    Excellent! Does the customer have to have Office or Word installed for this to work on their computers?
     
    zac439, Jul 1, 2007 IP
  10. smarketing

    smarketing Active Member

    Messages:
    117
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #10
    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
     
    smarketing, Jul 1, 2007 IP
  11. iMarketingGuru

    iMarketingGuru Well-Known Member

    Messages:
    486
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    160
    #11
    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.
     
    iMarketingGuru, Jul 1, 2007 IP
  12. zac439

    zac439 Notable Member

    Messages:
    3,074
    Likes Received:
    214
    Best Answers:
    0
    Trophy Points:
    260
    #12
    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.
     
    zac439, Jul 1, 2007 IP