Why is my vba macro working in debug f8 but not when running it it throws error when trying to cut a shaperange

I am trying to make a booklet imposition macro and it works when I press f8 multiple times it rearranges the pages by cutting and pasting but when I run the macro from scripts docker it stops at 3rd page when cutting please help

Parents
No Data
Reply
  • This usually happens because running with F8 (step-by-step) gives VBA time to refresh the document and update the ShapeRange selection, while running normally is too fast and the shape/object reference becomes invalid after a cut or paste. After you cut a shape, the original ShapeRange may no longer exist, so the next line fails. Try avoiding .Select and Selection.ShapeRange, store the shape in an object variable instead, and add a small DoEvents or short delay after cut/paste operations. Also loop backwards when moving pages/shapes because indexes change after each cut.

Children
No Data