Fields.Count returns 1 
Author Message
 Fields.Count returns 1

Hello,

I have encountered the following problem:

ActiveDocument.StoryRanges(wdTextFrameStory).Fields.Count

returns 1, but the document contains more than 1 text field.

Any idea?

Thanks,
Bernd



Fri, 12 Aug 2005 22:56:27 GMT  
 Fields.Count returns 1
Hi Bernd,

You only counting the fields in one of Word's StoryRanges. You can use
something like the following to get a more accurate count of all fields:

Dim myStoryRange As Range
Dim iFieldCount As Integer
For Each myStoryRange In ActiveDocument.StoryRanges
    iFieldCount = iFieldCount + myStoryRange.Fields.Count
Next myStoryRange
MsgBox iFieldCount

AFAIK, there are even some quirks with this. Have a look at the article
"Using a macro to replace text where ever it appears in a document including
Headers, Footers, Textboxes, etc." at
http://www.mvps.org/word/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm

HTH


Quote:
> Hello,

> I have encountered the following problem:

> ActiveDocument.StoryRanges(wdTextFrameStory).Fields.Count

> returns 1, but the document contains more than 1 text field.

> Any idea?

> Thanks,
> Bernd



Fri, 12 Aug 2005 23:56:30 GMT  
 Fields.Count returns 1
Dave,

Thanks for your answer. I did not know that there is more than one text
frame story in the document. So I cycle through them with the method
NextStoryRange and now it works!



Quote:
> Hi Bernd,

> You only counting the fields in one of Word's StoryRanges. You can use
> something like the following to get a more accurate count of all fields:

> Dim myStoryRange As Range
> Dim iFieldCount As Integer
> For Each myStoryRange In ActiveDocument.StoryRanges
>     iFieldCount = iFieldCount + myStoryRange.Fields.Count
> Next myStoryRange
> MsgBox iFieldCount

> AFAIK, there are even some quirks with this. Have a look at the article
> "Using a macro to replace text where ever it appears in a document
including
> Headers, Footers, Textboxes, etc." at
> http://www.mvps.org/word/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm

> HTH



> > Hello,

> > I have encountered the following problem:

> > ActiveDocument.StoryRanges(wdTextFrameStory).Fields.Count

> > returns 1, but the document contains more than 1 text field.

> > Any idea?

> > Thanks,
> > Bernd



Sat, 13 Aug 2005 00:29:35 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Select distinct on 1 field but returns multiple fields

2. Counting records returned by SQL Select statement

3. Counting records returned in a query

4. Return the count of replacments made

5. detecting hard carriage return's on line counting macro

6. counting tabs & hard returns in a document

7. Counting Rows returned from an SqlDataReader

8. Counting Records Returned from a Query

9. ExecuteSQL / ODBC API does not return row count

10. Counting returned records...

11. Counting Records Returned from a Query

12. HELP! Counting carriage returns in multiline text box

 

 
Powered by phpBB® Forum Software