Using VB .NET to iterate through a Fields Collection within a Microsoft Word Document ?

  • Thread starter Thread starter news.zen.co.uk
  • Start date Start date
N

news.zen.co.uk

Hi Guys,

Am wanting to iterate through a set of Mailmerge Fields within a MS-Word
document using VB .NET. Here's a fragment of code that (should) do this!

Dim WordDoc As Word.Document =
WordApp.Documents.Add("Test.doc")
WordDoc.Activate()
Dim Field As Word.Field
Dim C As Integer = 1
While C <= WordDoc.Fields.Count
Field = WordDoc.Fields.Item(C)
Field.Select()
C = C + 1
End While

However, I've noticed that not all the fields are picked up, suspect it's
this line that's the problem...

Field = WordDoc.Fields.Item(C)

Although I don't understand why. In the debugger, C runs through as a
sequence, i.e. 1,2,3,4,5,6 etc

'For Each Field In Word.Fields' doesn't seem to work.

Any help appreciated.

Regards,

Shaun
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top