XL file opened using automation - how close?

  • Thread starter Thread starter xp
  • Start date Start date
X

xp

I have a program that is run by Scheduled Task. This program opened an XL
file using automation as designed, however, now the file is hanging open and
I can only get to it "read only".

How can I regain control over this file and close it?

Thanks!
 
If you have a scripting tool use the below code. OR .Paste the below code to
a notepad and save as <somefilename>.vbs. From explorer double click the file
to execute/


Dim appExcel
Set appExcel = GetObject(, "Excel.Application")

If Not appExcel is Nothing Then
appExcel.DisplayAlerts = False
appExcel.Quit
End If
 
Sure, you can..

Dim appExcel,WB

On Error Resume Next
Set appExcel = GetObject(, "Excel.Application")
On Error Goto 0

If Not appExcel is Nothing Then
Set WB = appExcel.Workbooks("MyBook.xlsm")
WB.Close False
End If

Set WB = Nothing
Set appExcel = Nothing
 
Back
Top