Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
C_Haines_ENG
452 Views, 9 Replies

Cannot Close Excel File that was created with iLogic

I cant for the life of me figure out what im doing wrong here, and I'm assuming the problem is that excel is still being controlled somehow by Inventor after the code is run, but I cant seem to find out why or how. Below is a simplified code used to create, and then close an excel file. 

 

It creates it fine but attemping to close it will throw an error saying its still in use by another application.

 

FileDIR = "C:\BOM Calculator\PART_BOM.xlsx"

excelApp = CreateObject("Excel.Application")
excelApp.Visible = True
excelApp.DisplayAlerts = False
	
excelWorkbook = excelApp.Workbooks.Add

excelApp.Columns.AutoFit  
excelWorkbook.SaveAs(FileDIR)
excelApp.Application.Visible = True

excelApp = Nothing

'Ask If You Want to Close Excel File
Question = MessageBox.Show("Close Excel File?", "Title", MessageBoxButtons.YesNo)

If Question = vbYes

Try
	excelApp = GetObject("Excel.Application")
		For Each wb As Object In excelApp.workbooks
			MessageBox.Show(wb.fullname)
	        If UCase(wb.fullname) = UCase(FileDIR)
				wb.Save 
				wb.Close   
	        End If
	    Next
Catch
Finally
	excelApp = Nothing
End Try

End If

 

Do I not have enough SOMETHING = NOTHINGS ?

 

Any help would be appreciated.