The error you have been receiving is due to writing to file name and not to file-pointer as Rlx mentioned above, so I rewrote 'your' codes in another way and hope you don't mind since the following code and is more than enough and faster than converting safearray to list and so on.