Quote:
Originally Posted by Guessed
The code looks about right.
Is the last thing in your test document red text?
If you add this following line before myRange.Collapse, what is special about the selection when you step through the code?
myRange.Select
|
Hi, thanks for your response. No, the last text in the document is not red. It's just the regular automatic font color. The test document I'm using is all in normal with no styles or formatting at all.
I tried adding the line you suggested, but the only difference seems to be that when I step through the code I can see that the text in red is selected, but the result of the macro is the same whether I use that line or not. It just ends up in an infinite loop and includes those weird question mark in the box symbols in the index codes. With the exception of the very first index code that gets inserted.
I've been experimenting some more, and I think the problem might be that when the index code gets inserted, the curly braces surrounding it are red, so when it goes to move on to the next instance of red text, it stops on the index code and inserts another index code based on that, and it just keeps going.
Is the solution to somehow turn the newly inserted index code font color to wdAuto? I've tried doing that in several different ways, but I can't get it to work.