Keith Howard
Active member
- Joined
- Jan 28, 2010
- Messages
- 28
- Programming Experience
- 5-10
Hello,
I have the below loop that iterates through each character in a Word document. (The magic 4 is because I am interested in evaluating each four-character block of text in the document.) I am outputting CurString to the immediate Window and it is working fine until it gets to a field (such as the automatically generated table of contents) at which point it crashes. (As the CurChar count increases, and the four character block approaches the field, the "four" character block reduces in size (strangely) until it becomes "Nothing" at which point the code crashes.)
Basically, my aim is to trying to iterate in that loop to find a Reference field and then find the value of the target reference within the Reference field. Basically, in the above loop, I need to figure out how to identify the CurChar at the start of the field, assign the value of the field to a variable (and I would then do other logic relating to my current task), and somehow skip past the field, avoiding the crash, and continue with further loop iterations.
I am using MS Word 2013 and VS 2013 Professional.
Any help would be greatly appreciated.
Many thanks,
Keith
I have the below loop that iterates through each character in a Word document. (The magic 4 is because I am interested in evaluating each four-character block of text in the document.) I am outputting CurString to the immediate Window and it is working fine until it gets to a field (such as the automatically generated table of contents) at which point it crashes. (As the CurChar count increases, and the four character block approaches the field, the "four" character block reduces in size (strangely) until it becomes "Nothing" at which point the code crashes.)
For CurChar As Integer = 0 to NumberOfCharsInDocument CurString = Document.Range(CObj(CurChar), CObj(CurChar +4)).Text Next
Basically, my aim is to trying to iterate in that loop to find a Reference field and then find the value of the target reference within the Reference field. Basically, in the above loop, I need to figure out how to identify the CurChar at the start of the field, assign the value of the field to a variable (and I would then do other logic relating to my current task), and somehow skip past the field, avoiding the crash, and continue with further loop iterations.
I am using MS Word 2013 and VS 2013 Professional.
Any help would be greatly appreciated.
Many thanks,
Keith
Last edited by a moderator: