Some problem about macro scripts

I have written some macro scripts and tried to use some buttons to call them.
but I find that when I click these buttons the scripts execute line by line,that
means I can not get back to the previous step by the shortcut "Ctrl+Z", in max listener these macro scripts works well and have no such problem.
Is these any way could get rid of this?