at which point do you get the error?
on what line?

or when I try to run it from a macro
how are you calling from a mzcro?