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
in reply to: WCrihfield

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.