Hello Josh!
So I have encountered the same problem when creating addins. I don't know about the copy in the temp folder, but Excel still runs in the background. I tried to close the workbook, then quit the app, then empty the objects, nothing worked.
I tried everything and then in deepest end of google I've come across an article, which, of course, I can't seem to find now.
The gist of it was this: When you are using the Excel application outside of excel, relative references does not seem to work, because excel still "thinks" it will be needed in the future so it keeps the application open.
Relative reference for example:
range("A2") etc.
Now if you are in another application you should always put the necessary parent object before it like this:
worksheet.range("A2") but what worksheet, you have to have a workbook open, but what workbook, you need to run a Excel application for this.
In my case I did the following:
'Created the reference to a new Excel application
Dim oExcel As New Excel.Application
'Created a new workbook
Dim oWB As Excel.Workbook
oWB = oExcel.Workbooks.Add
'Set it to visible so I can see what's happening
oExcel.Visible = True
'Created the reference to a worksheet
Dim oWS As Excel.Worksheet
Then
oWS = oWB.ActiveSheet
or
oWS = oWB.Sheets(1)
or whichever sheet you want to work with in your case the ScrewFactory.Worksheet
And after this I use everything with this reference, for example:
oWS.range("A2").value 2 = whatever you want to.
When you are outside of excel (in visual studio and you are just using the excel application just like you are using Inventor application you have to specifically reference your objects, where did they come from)
Now, in your case:
I can see that iParts have this property ExcelWorksheet, but you still have to reference that.
So I would create an Excel application (see above)
Then reference to the workbook (since you could have multiple workbooks running, you have to specify which one do you wanna work with) then you can use that worksheet object.
In the API it says: iPartFactory.ExcelWorkSheet() As Object
Now object is the least specific object there is.
So in your code before this
Dim getSheet As Excel.Worksheet = ScrewFactory.ExcelWorkSheet
I would create an excel application object, then a workbook application object then you can follow up with your
getSheet object which I can see is a Worksheet type.
So it would go like this:
'Create the reference to a new Excel application
Dim oExcel As New Excel.Application
'Create a new workbook
Dim oWB As Excel.Workbook
oWB = oExcel.Workbooks.Add
'Set it to visible so I can see what's happening
oExcel.Visible = True
'Created the reference to a worksheet
Dim getSheet as Excel.Worksheet = ScrewFactory.ExcelWorkSheet
Now when you type: getSheet.Range("A2").value2 the program will know which excel application, which workbook and what sheet you are referring to.
Oh and don't use the below version:
Dim oXLApp As Object
oXLApp = CreateObject("Excel.Application")
I hope this helps, it worked for me after dealing with this problem for over 4 days and it kinda makes sense.
Accept it as a solution if it helped, or give it a thumbs up 🙂