Wednesday, 12 October 2016

excel - Workbook is not closing when using Workbook.Close method

I'm trying to open and then close a workbook but my problem is after using Workbook.close method the workbook remains open and can only be killed by task manager.

I found the answer from the below link VBA won't close workbooks opened programatically
but for my application it doesn't work...
Here the code:



Private Function writeInWB(myFile as String) As Variant
Dim xl0 As New Excel.Application
Dim xlwBBGTerm As New Excel.Workbook
Application.ScreenUpdating = False
Set xlwBBGTerm = xl0.Workbooks.Open(myFile)
GoTo ErrorHandling

ErrorHandling:
Application.ScreenUpdating = True
If xl0.Workbooks.Count > 0 Then
xlwBBGTerm.Close SaveChanges:=False
xl0.Quit
End If
End Function

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...