#1   Report Post  
Posted to microsoft.public.word.docmanagement
Tywardreath Tywardreath is offline
external usenet poster
 
Posts: 4
Default Word Count - help

Hi

I have a piece of VBA code that I'd like to modify, but I really don't know
how. This is the code:

Sub InsertWordCount()
Dim oRange As Word.Range
Dim sBookmarkName As String

sBookmarkName = "WordCount"
With ActiveDocument
Set oRange = .Bookmarks(sBookmarkName).Range
oRange.Delete
oRange.InsertAfter Text:=Format(.Sections(2).Range.ComputeStatistics
(wdStatisticWords), "0")
.Bookmarks.Add Name:=sBookmarkName, Range:=oRange
End With
End Sub

What the code does is that it does a word count on a specific section (in
this case section 2), and then it returns the result into an existing
bookmark called "WordCount".

Somehow I'd like to get the resulting number to be surrounded by another
bookmark (e.g. real). I'd like to do that in the VBA code. Then I have a
formula which will calculate if I am over or under the desired word count.
The formula I hope to use is: {if {real} 10000 "more than 10000" "less than
10000}.

I'm not fussed if the formula is in the VBA or not.

Appreciate any help that can be offered.

Cheers, Ty.



  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default Word Count - help

All you need to do that is another .Bookmarks.Add line after the first
one, like

.Bookmarks.Add Name:="real", Range:=oRange

But there's no reason to make a second bookmark covering the same
range. Just use the bookmark named WordCount that's already being
inserted:

{if {WordCount} 10000 "more than 10000" "less than 10000}

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Thu, 20 Jul 2006 16:36:01 -0700, Tywardreath
wrote:

Hi

I have a piece of VBA code that I'd like to modify, but I really don't know
how. This is the code:

Sub InsertWordCount()
Dim oRange As Word.Range
Dim sBookmarkName As String

sBookmarkName = "WordCount"
With ActiveDocument
Set oRange = .Bookmarks(sBookmarkName).Range
oRange.Delete
oRange.InsertAfter Text:=Format(.Sections(2).Range.ComputeStatistics
(wdStatisticWords), "0")
.Bookmarks.Add Name:=sBookmarkName, Range:=oRange
End With
End Sub

What the code does is that it does a word count on a specific section (in
this case section 2), and then it returns the result into an existing
bookmark called "WordCount".

Somehow I'd like to get the resulting number to be surrounded by another
bookmark (e.g. real). I'd like to do that in the VBA code. Then I have a
formula which will calculate if I am over or under the desired word count.
The formula I hope to use is: {if {real} 10000 "more than 10000" "less than
10000}.

I'm not fussed if the formula is in the VBA or not.

Appreciate any help that can be offered.

Cheers, Ty.


Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reveal codes in a word document FUN101 Microsoft Word Help 4 May 16th 23 08:47 PM
Why dont MS just f**king re-write Word from scratch? Its dogsh*t Word Hater Microsoft Word Help 33 May 5th 23 02:52 PM
Change paper size; Word changes to invalid margins OhioTech New Users 10 July 6th 06 02:00 PM
WP merge file to Word sstires Tables 4 February 14th 06 06:26 PM
How can Word display full path of a file in the title bar? SAsif Microsoft Word Help 1 January 26th 06 04:32 PM


All times are GMT +1. The time now is 01:12 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"