I also had this issue. One minute the code was working, the other it wasn't.
This error occurs when there is no workbooks opened (Workbooks.Count = 0). You need to add a dummy Workbook in order to add the AddIn.
I ended up finding the solution to this question in another post (with a code example). I leave my reply here as I found this post first.