Results 1 to 15 of 15
  1. #1
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dynamic word count? (Word 2003 SP-1)

    Hi all

    I sorely miss Woody's freebie Word Counter for WOPR (2000 I think?), of which Word 2003 contains a pale imitation in the form of the "Word Count" toolbar. The key drawback of this is that it doesn't update itself dynamically - you have to click the "Recount" button for it to work.

    I've Googled the net and scoured the Lounge for a solution to this, and have found a number of macros that purportedly display a dynamic word count in various places: in the status bar, on the Word window title bar or even as a button on the "Formatting" toolbar (the latter of which you can find here: http://wordtips.vitalnews.com/Pages/T1421_...rd_Counts.html)

    Unfortunately, none of these worked very well for me in Word 2003 - they either didn't work at all, or did so intermittently (e.g. the toolbar solution needed to be started with a manual click each time, no matter how hard I tried to run the macro automatically within AutoNew or AutoExec).

    Do any of you very resourceful folks have any ideas? I don't much care where it's positioned on the screen, and it doesn't even need to be 100% accurate all the time (I realise that counters triggered by over-enthusiastic timers exact a performance price) - it just needs to work on the "main" body of the text (without header / footers, etc) automatically and without needing to be initiated manually.

    From past experience, I'm confident that one or more Lounge denizens will have the perfect solution - so thanks in advance!

    Cheers

    Neil

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Dynamic word count? (Word 2003 SP-1)

    There's a lengthy discussion about displaying an up-to-date word count in the thread starting at <post#=114258>post 114258</post#>. The following was devised by <!profile=Klaus Linke>Klaus Linke<!/profile> and <!profile=Rory>Rory<!/profile>. If you want to use it, copy this code into your Normal.dot and run SetKeyBindings once.

    Sub SetKeyBindings()
    CustomizationContext = NormalTemplate
    KeyBindings.Add KeyCategory:=wdKeyCategoryMacro, _
    Command:="CountInStatusBar", _
    KeyCode:=wdKeySpacebar
    End Sub

    Sub CountInStatusBar()
    Selection.TypeText " "
    StatusBar = "Words: " & ActiveDocument.BuiltInDocumentProperties(wdPropert yWords)
    End Sub

  3. #3
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dynamic word count? (Word 2003 SP-1)

    Hans hi

    Many thanks for your prompt and helpful reply.

    I had actually seen that thread before posting my message and tried the code. I thought it wasn't working, but now that I understand it a bit better, I can see that it was working perfectly and that I wasn't paying attention!

    As I'm not a programming type, perhaps you could advise me: could this macro be adapted to place the count somewhere less critical so that it could remain on screen, just getting updated whenever the space key is hit? In its present form, it is cleared by any keyboard output or a mouse click.

    As I write for a living - and often to very rigid word count limits - it's very helpful to have it displayed persistently (which is exactly what the Word Counter in WOPR2K used to do).

    Thanks again

    Neil

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Dynamic word count? (Word 2003 SP-1)

    The following is a quick hack; it would need polishing if you want the word count to be updated when you switch between documents etc.

    The following macro will create a custom toolbar button in the Standard toolbar; you can put it in another toolbar if you like. You need to run this macro only once.

    Sub CreateMyButton()
    CustomizationContext = NormalTemplate
    With CommandBars("Standard").Controls.Add(msoControlBut ton)
    .Tag = "WordCountLabel"
    .Style = msoButtonCaption
    End With
    End Sub

    Change the SetKeyBindings macro to

    Sub SetKeyBindings()
    CustomizationContext = NormalTemplate
    KeyBindings.Add KeyCategory:=wdKeyCategoryMacro, _
    Command:="CountInToolBar", _
    KeyCode:=wdKeySpacebar
    End Sub

    and run it once.

    Change the CountInStatusBar macro to:

    Sub CountInToolBar()
    Selection.TypeText " "
    CommandBars("Standard").FindControl(Tag:="WordCoun tLabel").Caption = _
    "Words: " & ActiveDocument.BuiltInDocumentProperties(wdPropert yWords)
    End Sub

  5. #5
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Figured it out!

    Hans

    Please disregard my last plea for help - I have figured it out all on my own!

    Displaying the Word count variable on the Window caption was pretty easy - then I just created an AutoClose macro (to remove the count when the document is closed) and called my new "CountInTitleBar' macro in both AutoNew & AutoOpen to reset it for a new or opened document. It seems to work a treat.

    Thanks for your inspiration!

    Neil

  6. #6
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dynamic word count? (Word 2003 SP-1)

    Thanks once more Hans

    The toolbar looked like a more elegant solution, so I backed up my own mods that made it work in the titlebar, deleted them from Normal.dot and pasted in your code exactly as you posted it... but nothing displayed until I ran the "CountInToolBar" macro, and even then, it doesn't seem to refresh itself. In fact the value displayed at the previous time the macro was run persists until the next time.

    I think that the resets could probably be fixed pretty easily in places like AutoNew & AutoClose as I did with my own attempts - the main challenge is to get it to update dynamically. It would be awesome to get this one working.

    On a related matter, would you have any idea why my Normal.dot grows by several hundred kb everytime I make changes to these macros? Only a few months ago, I recreated it from a 'blank slate' & got it down to about 100k - it is now 4.5 Mb, which has to have some performance impact.

    Thanks again

    Neil

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Dynamic word count? (Word 2003 SP-1)

    Have you run KeyBindings again with the new name of the macro (CountInToolBar)? It works OK for me.

    Normal.dot shouldn't grow that fast. Mine contains lots of macros and is some 150 KB. Is "Allow Fast Saves" checked in the Save tab of Tools | Options...? If so, turn it off, it causes all kinds of problems.

  8. #8
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dynamic word count? (Word 2003 SP-1)

    Hans

    The key binding must have been the problem - it works fine now... except for the fact that my normal.dot grown by about 0.5Mb in size just tonight while I have been playing with this! (And I have had several such sessions in the last few days.)

    It's probably no coincidence that Word is now quite sluggish - it takes a few seconds before it prompts to save a document before closing. I'm sure the word counter is not responsible for this.

    As a long time Woody reader, I've always had fast saves turned off. I have no idea what this problem could be, but the template that was about 100k 2 months ago is now just under 4.5Mb! It contains a few styles, some autotext (including a very small GIF of my signatures) and perhaps 8 or 9 macros all of which are shorter than those you have sent to me tonight.

    I don't get it - in the absence of any other information, I'll probably have to back up its toolbars and other customisations and rebuild it again :-(.

    Once again Hans, thanks so much for your help - this word counter thing is very close to what I need now.

    All the best

    Neil

  9. #9
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Dynamic word count? (Word 2003 SP-1)

    4.5 MB does sound ab-Normally large. There are threads on this board or on the VBA board referring/linking to a "code cleaner" that can help reduce bloat on the VBA side of the house, but AutoText and other stuff would have to be handled manually, as far as I know.

  10. #10
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dynamic word count? (Word 2003 SP-1)

    Thanks for the input Jefferson - yeah, I know it's waaay too big - the only thing I can tell you is that it grows before my eyes as I tinker around with macros (as I have been tonight), growing like Godzilla every time I save the template.

    I think that I'll rename Normal.dot, restart Word & create a new one, importing styles and autotext from my bloated version. I've exported the macros to a .bas file from the VB editor and will re-import them into the new template the same way (I figure that's less likely to drag in tons of hidden code than if I use the Organiser function for the macros.

    The only thing I'm not sure how to do is copy toolbars between the soon-to-be-old template and the new one - I remember this was the only time-consuming bit when I did this two months ago. The Organiser doesn't seem to want to help with them - do you have any ideas?

    And of course, I will keep a back up of the new, slimmer version that I can rollback to later!

    Cheers

    Neil

  11. #11
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Dynamic word count? (Word 2003 SP-1)

    I think copying toolbars is not supported with the built-in tools. But we've had threads with different ideas how to do it, perhaps more on the VBA board than on this one.

  12. #12
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dynamic word count? (Word 2003 SP-1)

    Yup - I found a tip (yours if I'm not mistaken!) explaining this process - in fact I've already done the template rebuild since my previous post - except for figuring out how to import my old key customisations - searching the borads for that as I type!

    Cheers

    Neil

  13. #13
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dynamic word count? (Word 2003 SP-1)

    Hans

    Just a quick one now that I have everything sorted out (including my bloated template, which I have now rebuilt - didn't take very long at all).

    I thought I understood the code in this macro, but for some reason, whenever I open a document or create one with the counter active, it inserts a space at the beginning of the document - which means every document prompts for saving, even if I haven't made any genuine changes. It's not a major thing, but it would be even better if it didn't.

    For your information, I call the main macro in AutoNew and AutoOpen and force a display of a literal zero value in AutoClose.

    Any suggestions?

    Cheers

    Neil

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Dynamic word count? (Word 2003 SP-1)

    You only need to run SetKeyBindings and CreateButton once.If you want to reset the count when a document is created or opened, you shouldn't call CountIntoolBar, for that is the replacement code for the space bar. You could create a separate macro

    Sub ResetCount()
    CommandBars("Standard").FindControl(Tag:="WordCoun tLabel").Caption = _
    "Words: " & ActiveDocument.BuiltInDocumentProperties(wdPropert yWords)
    End Sub

    and call that in AutoNew and AutoOpen.

    BTW If you want to make it really fancy, you would need to create application-level event procedures to adjust the word count when you switch between documents. See for example <post#=203498>post 203498</post#>.

  15. #15
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dynamic word count? (Word 2003 SP-1)

    Hans' macro starts with
    <font face="Georgia">Selection.TypeText " "</font face=georgia>
    thus inserting a space at the start of the document, causing the Saved status to be changed. To work around that, you could add
    <font face="Georgia">ActiveDocument.Saved = True</font face=georgia>
    right after the call to that Sub in your AutoOpen Sub. This stop the Save-prompt - if nothing else changes the document of course.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •