Message 1 of 10
Cannot Close Excel File that was created with iLogic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.