You have cells that work and others that don't ... work out what the differences between those cells are to determine what the problem is. It is not weird to call functions from Cells formulae.
Debugging is good - it is also not weird. "Couldn't jump out of the function" - then work out where it went (use F8 to step through). Take a note of which values are making it hang. Make sure you have a MoveNext in all paths through any loops.
The following line of code is probably wrong
If Not dic.exists(spath) Then
Why do I think it is wrong ... because you then try to connect to the file in
having just determined that the file does not
will return True if the file exists. So putting the
in front of it will return False if the file exists.