XL file opened using automation - how close?

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!
 
J

Jacob Skaria

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
 
J

Jacob Skaria

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top