Quark: Script won't work past a few pages

Hello all,

This is a continuation of a previous project for which I received help through this BBS. I can not locate my old thread so I am beginning anew.

I have a script to search a Quark doc, find style sheets that hold a file name, make a new picture or text box with that file name, and paste it into text over top of the paragraph.

My script is sometimes missing paragraphs it should process, pasting in the wrong place, and only processes about 5 pages of a 20 page document. I have given it 75 megs.

I do not know why it will not work? It seems to be correct.

Any help would be so greatly appreciated! A lot of the copy on my script came from the person who helped me and I am so sorry that I can not remember your name. I hope you see this and will remind me so the community here will know your name.

Thank you all.

Steven.

global newBox
global hiresFileNamePath
global x
global p
global j
global thisSize
global i

set hiresFileNamePath to choose folder with prompt "Pick Hi Res folder for this title. "
–set numberList to {“1”, “1"”, “2”, “2"”, “3”, “3"”}
set numberList to {“1”, “2”, “3”}
set x to {}
set p to {}
set j to {}
set thisSize to {}

set newBox to “”

tell application “QuarkXPress™ 4.11”
try
activate
tell document 1
repeat with p from 1 to (count of every page)
tell page p
repeat with j from 1 to (count of every text box)
tell text box j
repeat with i from 1 to (count of every paragraph)
try
if name of style sheet of paragraph i is in (numberList as text) and ¬
first character of paragraph i is not return then
if last character of paragraph i is return then
set x to contents of paragraph i as string
set thisSize to (name of style sheet of paragraph i) as integer
my makeBox(p, j, i, thisSize, x, hiresFileNamePath)

									end if
								end if
							end try
						end repeat --repeat of paragraph 
					end tell --text box j 
				end repeat --repeat of text box 
			end tell -- page p 
		end repeat --repeat of page 
	end tell --end tell document 1
end try

end tell

on makeBox(p, j, i, thisSize, x, hiresFileNamePath)
tell application “QuarkXPress™ 4.11”
tell document 1
tell page p
show --Show the page
try
set newBox to “” --Empty variable
–Create a new picture box
set newBox to make new picture box at beginning with properties ¬
{name:x, bounds:{“0"”, “0"”, “” & thisSize & “”“, “2.25"”}, color:¬
“white”, frame:{color:“black”, style:solid, width:“0.25 pt”}, runaround:none runaround}
set image 1 of newBox to (”" & hiresFileNamePath & x)
set bounds of image 1 of newBox to exact fit
on error
–If an error and exists a new picture box then delete that last one
if newBox is not “” then delete newBox
set newBox to “” --Empty variable
try
–Create a new text box
set newBox to make new text box at beginning with properties ¬
{name:x, bounds:{“0"”, “0"”, “” & thisSize & “”", “2.25"”}, color:¬
“white”, frame:{color:“black”, style:solid, width:“0.25 pt”}, runaround:none runaround} --of page thisPage
set story 1 of newBox to x
on error
if newBox is not “” then delete newBox
error “Error when try to create a new picture box and new text box” number 9000
end try
end try
end tell --end tell page

		try
			set selection to null
			set tool mode to drag mode
			select newBox
			cut
			set tool mode to contents mode
			--Delete the name of image in the text 
			set selection to insertion point before character 1 of paragraph i of ¬
				text box j of page p --story 1 of 
			delete text from character 1 to character -2 of paragraph i of ¬
				text box j of page p --story 1 of 
			paste
			set selection to null
		on error -- 
			error "Error when try to cut and paste the box into the text" number 9002
			--end try
			--end tell
			(*on error MsgErr number NroErr
	if NroErr is not -128 then ¬
		display dialog "" & NroErr & " : " & MsgErr with icon 0*)
		end try
	end tell
end tell

end makeBox

Oops! Forgot:

AS 1.6
OS 9.2.2
Quark 4.1.1
Frustration 6 out 10

Thank you.

Steven