11-07-2023
12:38 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
11-07-2023
12:38 PM
excelApp.Quit was the solution, doesn't even need the excelApp = Nothing, that actually screws it up more.
Here is the final code, works perfectly. Interestingly enough it still doesnt show the message box with the name of the document, closes it anyway. *shrug*
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 'Ask If You Want to Close Excel File Question = MessageBox.Show("Close Excel File?", "Title", MessageBoxButtons.YesNo) excelApp.Quit '<- THIS WAS REQUIRED 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 excelApp.Quit End If Next Catch End Try Else End If