11-08-2023
12:02 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
11-08-2023
12:02 PM
I am now seeing what you mean, and yes the code doesnt work anymore...
FileDIR = "C:\BOM Calculator\PART_BOM.xlsx"
'[ TRY TO CLOSE EXCEL FILE FIRST
Try
excelApp = GetObject(, "Excel.Application")
For Each wb As Object In excelApp.workbooks
If UCase(wb.fullname) = UCase(FileDIR)
'wb.Save
'wb.Close
excelApp.Quit
End If
Next
Catch : End Try
']
'[ CREATE NEW FILE AND INSERT DATA
excelApp = CreateObject("Excel.Application")
excelApp.Visible = True
excelApp.DisplayAlerts = False
excelWorkbook = excelApp.Workbooks.Add
excelApp.Columns.AutoFit
excelWorkbook.SaveAs(FileDIR)
excelApp.Application.Visible = True
'Insert data into Excel.
With excelApp
.Range("A1").Select
.ActiveCell.Value = "Hello, Cole"
End With
']
I realize that it wasnt closing because the loop found it again, it was closing because it was still attached to the first excelApp. I am dumb.