Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
Hi,
I need to create a field which counts the number of words in the preceeding paragraph. And I'm actually completely stuck - VBA to navigate around a document not something I have ever worked with. I'm pretty comfortable with fields, but it's the paragraph selection that loses me. Thanks in advance Andy |
#2
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
It can't be done with fields alone. You could use a DOCVARIABLE field and
then use VBA to load the number of words into the variable To get the number of words in the ith paragraph of the document, you would use ActiveDocument.Paragraphs(i).Range.Words.Count If you had a field { DOCVARIABLE varparai } you could use With ActiveDocument .Variables("varparai").Value = .Paragrapsh(i).Range.Words.Count .Range.Fields.Update End With to get the number of words to be displayed in that field. -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP wrote in message oups.com... Hi, I need to create a field which counts the number of words in the preceeding paragraph. And I'm actually completely stuck - VBA to navigate around a document not something I have ever worked with. I'm pretty comfortable with fields, but it's the paragraph selection that loses me. Thanks in advance Andy |
#3
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
On Mar 21, 1:04 pm, "Doug Robbins - Word MVP"
wrote: It can't be done with fields alone. You could use a DOCVARIABLE field and then use VBA to load the number of words into the variable To get the number of words in the ith paragraph of the document, you would use Hi Doug, Thanks for the suggestion - sounds good. One question remains, though! Each field needs to refer to the paragraph above it - how do I work out the number of the paragraph in the document relative to the position of the field? Thanks Andy |
#4
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
The following macro will add a field that displays [## words] at the end of
each paragraph in a document: Dim i As Long Dim varname As String Dim frange As Range With ActiveDocument For i = 1 To .Paragraphs.Count varname = "Para" & i .Variables(varname).Value = " [" & .Paragraphs(i).Range.Words.Count & " words]" Set frange = .Paragraphs(i).Range frange.End = frange.End - 1 frange.Collapse wdCollapseEnd .Fields.Add Range:=frange, Type:=wdFieldDocVariable, Text:=varname Next i .Fields.Update End With -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP wrote in message oups.com... On Mar 21, 1:04 pm, "Doug Robbins - Word MVP" wrote: It can't be done with fields alone. You could use a DOCVARIABLE field and then use VBA to load the number of words into the variable To get the number of words in the ith paragraph of the document, you would use Hi Doug, Thanks for the suggestion - sounds good. One question remains, though! Each field needs to refer to the paragraph above it - how do I work out the number of the paragraph in the document relative to the position of the field? Thanks Andy |
#5
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
On Mar 22, 7:33 am, "Doug Robbins - Word MVP"
wrote: The following macro will add a field that displays [## words] at the end of each paragraph in a document: ...snip... -- Hope this helps. Excellent! Thanks for your help, that's just what I was after. |
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Can I set word count to not count words with three letters less? | Microsoft Word Help | |||
count and show number of words in a line | Microsoft Word Help | |||
Sudden loss of words when inserting words.... | New Users | |||
Formatting merge fields: inserting a paragraph mark before a field | Mailmerge | |||
Inserting a field containing the number of pages in another sectio | Microsoft Word Help |