Using LotusScript to get word count MS Word

Posted on 2003-03-14
Medium Priority
Last Modified: 2013-12-18
I'm using code in LotusScritp to get the word count from a Word document. Briefly, w/o the error stuff it's just

     Set application = createobject("Word.Basic.8")
     wordCount = Application.GetDocumentProperty("Words")

This works, but the wordCount is not accurate.  I see from MS Knowledge Base 159791 that it's more accurate to get from Tools Word count dialog. They suggest.

     set wdDTWC = Dialogs(wdDialogToolsWordCount)
     dlgwordcount$ = wdDTWC.Words.

This works fine if your in Word and have a document open.  But how to you get this value from LotusScript using the application object?  

A more general question.  Is there a reference somewhere that lists everything you can call from the application object for Word in LotusScript?  Most of the stuff I try to do is not available and the commands that do work are usually different than what's in VBA in Word.

Question by:jsowle
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 63

Expert Comment

ID: 8139531
In Designer you have to switch to OLE Classes list.
There you can see all OLE servers, their properties and methods with parameter types.

You see the OLE Classes only when you click to objects which support LotusScript. For example you click in a Form on QueryOpen event and you can select OLE Classes. Or you can see it always in LotusScript agents.

Good luck,

LVL 63

Accepted Solution

Zvonko earned 300 total points
ID: 8139726
Oh, and you need the Word constants.

Const wdDialogToolsWordCount = 228 '\\(&HE4)

So the complet script looks like this:

Sub Click(Source As Button)
     Set WordApp = createobject("Word.Application")
     Const wdDialogToolsWordCount = 228 '(&HE4)
     Set wdDTWC = WordApp.Dialogs(wdDialogToolsWordCount)
     dlgwordcount$ = wdDTWC.Words
     Msgbox "Words: " & dlgwordcount$
End Sub


Author Comment

ID: 8139876
Great.  I had never used that part of the designer.  However I don't see in there anyway to get the actual methods and properties I need.  For instance "GetDocumentProperty" is not included anywhere that I can find.  I'm trying

Dim temp As Variant
Set temp = application.Dialog("wdDialogToolsWordCount")    
Call temp.execute
wordCount = temp.Words

But "execute is not an instance of temp"
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 8140014
We crossed communications.  I get Instance Dialogs does not exist with your code.  I think that must be because I'm using Word.Basic.8 instead of Word.Application for createobject.  Is there an equivalent for the dialogs command in WB 8?  If not, I'm also going to have to replace a bunch of other stuff.


Call application.StartOfDocument
Call application.EditFindClearFormatting
Call application.EditFindStyle("DocName")
Call application.EditFind("L:*","L:",0,0,0,1,0,0,1,0)
If application.EditFindFound = -1 Then
     Print "Document name found,  Adding TTN"
     Call application.EndOfLine()
     Call application.Insert(" (TTN " & docTTN & ")")
End If

I think I have seen an MS site which has replacement commands for WB8
LVL 63

Expert Comment

ID: 8140152
Moment please, we are here in LotusNotes topic area.
You asked how to call VB from LotusScript and I did show you some lookup methods.

Now you ask why Word.Application methods do not work in Word.Basic because you like the Work.Application code running but don't like to change Word.Basic part. Huh!!!

Hey, what is the problem to do WordsCount by using Word.Application and let the rest as is???


Author Comment

ID: 8140432
Don't get mad.  Sorry.  I was previously under the impression that you had to use Word Basic 8 commands in LotusScript.  I guess that was true in 4.5 but not in 5.x???  I'm beginning to get the picture.  I think I can figure it out from here.  You've been very helpful....and fast too. Thanks.
LVL 63

Expert Comment

ID: 8141813
You are welcome :-)

Small side note: LotusScript is an own extension of Visual Basic.
It has own classes and syntax extensions.
But it can communicate with other OLE interfaces and call their methods and change their property values.

If this is enough for you then grant please an A grading to one of my comments as an answer.



Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question