Advertisement

11.12.2007 at 01:27PM PST, ID: 22955659
[x]
Attachment Details

How can I find the location of a Field within an MS Word range?

Asked by PatternNut in Visual Basic Programming, Microsoft Word

Tags: vba, footnotes, location, word

Hi Experts,

I'm programming in VB6 / VBA and working with MS Word.  My program has a paragraph range which I know has a field within it.  However, I can't figure out where the field is in the range.  Is it at the beginning?  End?  Somewhere in the middle?  How many characters in?  I know there is field (of one type or another) because I used the code below:

Dim fld as Word.Field
Dim rng as Word.Range

For Each fld In rng.Fields
  If fld.Type = wdFieldPageRef Then
      msgbox "FieldPageRef"
  ElseIf fld.Type = wdFieldTOC Then
      msgbox "Table of Contents"
  elseif fld.type = wdFieldFootnoteRef
      msgbox "Footnote"        
  ElseIf fld.Type = wdFieldTOA Or fld.Type = wdFieldIndex Then
      msgbox "Other field"
  End if
Next fld

That works fine... In some of the cases, eg Table of Contents, I know that the field is the whole paragraph (in which case there is no issue locating it).  However, for others, like footnotes, I can't figure out where they are in the text.  The only thing I can think of is to test one character at a time because once inside of a field, the above code doesn't find the field at all.  However, that method would be very, very slow.  Is there a better way?

Thanks in advance,

PatternNutStart Free Trial
[+][-]11.12.2007 at 02:34PM PST, ID: 20268060

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.12.2007 at 02:51PM PST, ID: 20268166

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.12.2007 at 03:49PM PST, ID: 20268546

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Visual Basic Programming, Microsoft Word
Tags: vba, footnotes, location, word
Sign Up Now!
Solution Provided By: GrahamSkan
Participating Experts: 1
Solution Grade: A
 
 
[+][-]11.12.2007 at 04:07PM PST, ID: 20268652

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628