I have a workbook which is already opened and I want to close it. the code that i have is (see below) is not working. Anyone can share some inputs?
Code:
Function CloseExcel(sExcelFile As String) As Integer
Dim XLapp As New Excel.Application
Dim ObjXL As Excel.Workbook
On Error GoTo ErrorTrap
Set ObjXL = XLapp.Workbooks.Open(sExcelFile)
ObjXL.Application.Visible = True
ObjXL.Windows(1).Visible = True
ObjXL.Close
Set ObjXL = Nothing
Exit Function
ErrorTrap:
Debug.Print "(" & Err.Number & ") " & Err.Description
End Function