Loop macro for creating virtual ASM Structure

I am working on a macro the uses an indented BOM to create an assembly and creates virtual sub assembles that don't yet exist.

the macro creats the top assembly and level two virtual subassembles but i am having issues figuring out how to create a functioning loop that will make further subassemles.

this is the part of the code that seems to be failing when it loops to create a subassembly in my subassembly i get an error

Run Time Error '-2147417851(80010105)'

Automation Error

The Server Thew an Exception

status = SWAsm.InsertNewVirtualAssembly(swcomp)

My macro runs from Module1 then when a component isnt found then runs module2 which loops on itself as further components are not found.

I am new to writing macros so i am assuming i am probably doing something wrong in trying to loop.

SolidworksApi macros