Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Reveal codes in a word document | Microsoft Word Help | |||
Why dont MS just f**king re-write Word from scratch? Its dogsh*t | Microsoft Word Help | |||
Change paper size; Word changes to invalid margins | New Users | |||
WP merge file to Word | Tables | |||
How can Word display full path of a file in the title bar? | Microsoft Word Help |