About Me

Nick Hodge is a professional geek and digital diplomat for Microsoft in Australia. More info lives underneath the About Box...

Mr Nick Hodge
Nick Hodge 
(to learn how to correctly integrate microformats, how to this blog and book will help out)

Messenger me


How to add Live Messenger on your site

Ads


Blog Flair

View Nick Hodge's profile on LinkedIn
Top 100 Australian Blogs
Technology Blogs - BlogCatalog Blog Directory

Blogroll

« InDesign 2.0 Word count | Main | Scripting Colour Changes in Illustrator »

InDesign 2.0: Word Count using Visual Basic

By Nick Hodge | January 7, 2002

Adding a Word Count to InDesign 2.0

TextCounter (Win) on Adobe Studio Exchange

One of the features missing from InDesign since its first version is a word count feature. In a fit of quiet rage and sheer stupidity, I wrote this simple Visual Basic 6.0 application that pops up a small window displaying the word count of the current selected story.

There is a Timer named tLexLuthor that waits around for a period of time

[1008] 01 lois lane timer

Just in case the user doesn't want this turned on, there is a status button called bStart that toggles the timer tLexLuthor on and off.

[1009] 02 lois lane button

And finally there is a status field (read only) called lStatus. This is where the current word count is stored.

[1010] 03 lois lane label status

... And when running, this is how it looks.

[1011] 04 lois lane in action

The Visual Basic source that sits behind this small application is as follows:


Dim myInDesign As InDesign.Application

Dim myPub As InDesign.Document

'button named bStart (toggles on/off of Timer)

'lStatus as a label that contains the word count text

'tLexLuthor as a Timer object

Private Sub bStart_Click()
If (bStart.Caption = "Start") Then
bStart.Caption = "Stop"
tLexLuthor.Enabled = True
lStatus.Caption = ""
Else
bStart.Caption = "Start"
tLexLuthor.Enabled = False
lStatus.Caption = "waiting"
End If

End Sub

Private Sub tLexLuthor_Timer()
processEvent

End Sub

Private Sub processEvent()
Dim mySel As Object 'untyped object because we don't know what the selection is
On Error GoTo fail 'if anything goes wrong, don't call me
Set myInDesign = CreateObject("InDesign.Application")
Set myPub = myInDesign.ActiveDocument
Set mySel = myPub.Selection(1) 'a selection can be multiple objects, this time just get the first (and potentially only)
If (TypeOf mySel(1) Is InDesign.TextFrame) Then 'if it is a text frame, then
myCount = mySel(1).ParentStory.TextWords.Count 'get the word count from the text frame
ElseIf (TypeOf mySel(1) Is InDesign.InsertionPoint) Then 'or if its a insertion point, that is the user is typing
myCount = mySel(1).ParentTextFrame.ParentStory.TextWords.Count 'get the word count through the frame's text object
End If
lStatus.Caption = "word count: " & CStr(myCount) 'set the status
Exit Sub

fail:
lStatus.Caption = ""

End Sub

The project and executable is here:Lois Lane example downloadable (3K)

Possibly Related Posts:


Share the love:
  • Digg
  • Reddit
  • del.icio.us
  • Technorati
  • StumbleUpon
  • Bumpzee
  • Facebook
  • Live
  • NewsVine
  • TwitThis

Topics: mungenet |

2 Responses to “InDesign 2.0: Word Count using Visual Basic”

  1. InDesign 2.0 Scripts | nickhodge.com Says:
    September 5th, 2007 at 6:39 pm

    [...] InDesign 2.0: Word Count using Visual BasicNick HodgeScripting in InDesign 2.0 to add word count [...]

  2. InDesign CS: Prepress Overview | nickhodge.com Says:
    September 6th, 2007 at 8:03 am

    [...] only a word count: InDesign CS also counts sentences, lines and characters. No more need for InDesign 2.0: Word Count using Visual Basic! The above image depicts a text frame that contains a certain number of characters/words etc, and [...]

Comments