Getting a strange error with a visual basic script, only on a certain file though?

This is a script that among other things, creates a string of text from user input adding the words Cyan Magenta Yellow Black at the end. This is for marking plates with the respective colors. This script as far as I can tell, works fine in every file I've tried it on, except one which gives the above cryptic error. Hitting End in the dialog ends the script execution but Draw is then in a state that it can't be used and has to be closed. Doesn't crash, just doesn't update the screen.

Here's the relevant code that is causing the problem, it counts the words in the line of text and selects the relevant color name and applies the correct color to it:

Dim tr1 As TextRange, tr2 As TextRange, tr3 As TextRange, tr4 As TextRange
Dim wordcount As Long

wordcount = ActiveShape.Text.Story.Words.Count

Set tr1 = TxtInfo.Text.Story.Words(wordcount - 3)
Set tr2 = TxtInfo.Text.Story.Words(wordcount - 2)
Set tr3 = TxtInfo.Text.Story.Words(wordcount - 1)
Set tr4 = TxtInfo.Text.Story.Words(wordcount)

tr1.Fill.UniformColor.CMYKAssign 100, 0, 0, 0
tr2.Fill.UniformColor.CMYKAssign 0, 100, 0, 0
tr3.Fill.UniformColor.CMYKAssign 0, 0, 100, 0
tr4.Fill.UniformColor.CMYKAssign 0, 0, 0, 100

It gets hung on the first color assign for the Cyan word, "tr1.Fill.UniformColor.CMYKAssign 100, 0, 0, 0" if I comment that out, it gets hung on the next line for Magenta, and I presume from there on, I didn't test that far.

Again, this works fine in other files, just not this particular file for some reason. If I copy out the relevant objects to a new file, then it works fine, but in it's original file, it doesn't work. Kind of an odd thing and there is a work around but if I could find out what in this particular file is causing this issue, that would be nice to eliminate the problem.

Parents
No Data
Reply
  • I'm glad to read that you found a solution to the problem.

    For troubleshooting VBA macros, are you familiar with setting one or more break points in the VBA editor, and then using "Step Into" (F8) to step through the code one line at a time after a break point is encountered? And using the Locals Window to see what is going on with objects in your code as you do so?

Children