I moved the section adding the reference into a function, returning the error number and it worked. The only thing that I can figure out is that the Err object did not get reset, even though I used Err.Clear.

After putting the addfromfile into the function, I could run it without any problems.