Word Count - help

T

Tywardreath

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.
 
J

Jay Freedman

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
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top