![]() |
|
#1
|
|||
|
|||
![]()
Hi, is there anyway to link word count of individual chapters into a ToC?
Or failing that some means to effect a table that reports the word count in each chapter thanks |
#2
|
||||
|
||||
![]() Quote:
It could be done with a macro - provided each chapter can be differentiated by something such as a Section break.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Ok lets say each is seperated by a section break how then?
|
#4
|
||||
|
||||
![]()
As I said, with a macro. For example, the following macro will output a word-count for each Section at the end of the document.
Code:
Sub Demo() Dim Sctn As Section, StrCounts As String With ActiveDocument For Each Sctn In .Sections StrCounts = StrCounts & "Section " & Sctn.Index & ":" & vbTab & _ Sctn.Range.ComputeStatistics(wdStatisticWords) & vbCr Next .Range.InsertAfter StrCounts End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
![]()
Hi, thanks for that but when I run this it outputs the word count only of the final section, regardless of where the curser is, am I doing something wrong?
|
#6
|
||||
|
||||
![]()
I subsequently edited the code - try it now.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
![]()
Thanks that works well but how do I know link those figures into my ToC
|
#8
|
||||
|
||||
![]()
You can't (unless you include them in headings referenced by the TOC) - and why would you want to?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
![]()
Thanks again, one last question if I may, how do I create that heading in the ToC?
As to why, it is useful to me or it delays me getting on with what I should be doing ![]() |
#10
|
||||
|
||||
![]()
You could simply apply an appropriate heading Style to the macro's output, then update the TOC by clicking anywhere in it and pressing F9
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
![]()
Ok, so as I understand it I find what part of the macro is the output, which I presume I can do by trial and error and then tell it to be say, subtitle? As you can no doubt tell, I know nothing of these things you call macros, though I did change yours slightly to make it output at the top of the document rather than the bottom but that was just guess work
|
#12
|
||||
|
||||
![]()
I wasn't suggesting you make any modifications to the macro; only that you format the output that it has placed at the end of your document with an appropriate heading Style. Do note, too, that every time you run the macro, it will output a new set of stats. It won't delete any previous stats - which will get counted in the new total for the last Section.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
![]()
Oh, I see, is there not a way to instruct the macro to do the formatting?
|
#14
|
||||
|
||||
![]()
Sure one could, but that isn't what you had asked for. All you asked for originally was how to get the counts. I gave you a simple macro for that because I had no idea what you wanted to do with them after they were generated. For all I knew, you wanted to read & delete them or attach them to your actual headings.
I still don't see the point in generating this kind of stuff with a macro when you can get the word count for any range you're interested in just by selecting the range and looking at the word count stats on the status bar. That said, try: Code:
Sub Demo() Dim Sctn As Section, StrCounts As String, Rng As Range, TOC As TableOfContents With ActiveDocument For Each Sctn In .Sections StrCounts = StrCounts & "Section " & Sctn.Index & ":" & vbTab & _ Sctn.Range.ComputeStatistics(wdStatisticWords) & vbCr Next Set Rng = .Characters.Last With Rng .InsertAfter StrCounts .End = .End - 1 .Style = wdStyleHeading2 End With For Each TOC In .TablesOfContents TOC.Update Next End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#15
|
|||
|
|||
![]()
Yep, that works, many thanks
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
donaldadams1951 | Word VBA | 4 | 02-04-2015 03:54 PM |
![]() |
dynamictiger | Word Tables | 4 | 07-21-2014 10:16 PM |
Table of Contents | feature | Word | 10 | 04-09-2013 05:45 AM |
![]() |
ep2002 | Word | 4 | 06-20-2012 10:23 PM |
Table of contents | markos97 | Word | 0 | 10-26-2010 08:52 AM |