From: xp on
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!
From: Jacob Skaria on
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

--
Jacob (MVP - Excel)


"xp" wrote:

> Hi Jacob,
>
> Thanks; however, I should have been more clear in my original post, how can
> I do this programmatically? Is it possible to get a reference to the running
> instance from a separate file (say VBScript or XL) and close the file?
>
> If so how?
>
> Thanks again!
>
> "Jacob Skaria" wrote:
>
> > Did you try after closing Excel Application.
> >
> > If it is hidden instance from 'Task Manager'>close all 'Excel applications'
> > and then try
> >
> >
> > --
> > Jacob (MVP - Excel)
> >
> >
> > "xp" wrote:
> >
> > > 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!
From: Jacob Skaria on
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


--
Jacob (MVP - Excel)


"xp" wrote:

>
> Thanks so much Jacob! That works!
>
> May I just ask one last thing? Say my file name is "MyBook.xlsm" - is there
> a way to get a reference just to that file and close only that file?
>
> "Jacob Skaria" wrote:
>
> > Missed error handling...
> >
> > Dim appExcel
> >
> > On Error Resume Next
> > Set appExcel = GetObject(, "Excel.Application")
> > On Error Goto 0
> >
> > If Not appExcel is Nothing Then
> > appExcel.DisplayAlerts = False
> > appExcel.Quit
> > End If
> >
> > --
> > Jacob (MVP - Excel)
> >
> >
> > "Jacob Skaria" wrote:
> >
> > > 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
> > >
> > > --
> > > Jacob (MVP - Excel)
> > >
> > >
> > > "xp" wrote:
> > >
> > > > Hi Jacob,
> > > >
> > > > Thanks; however, I should have been more clear in my original post, how can
> > > > I do this programmatically? Is it possible to get a reference to the running
> > > > instance from a separate file (say VBScript or XL) and close the file?
> > > >
> > > > If so how?
> > > >
> > > > Thanks again!
> > > >
> > > > "Jacob Skaria" wrote:
> > > >
> > > > > Did you try after closing Excel Application.
> > > > >
> > > > > If it is hidden instance from 'Task Manager'>close all 'Excel applications'
> > > > > and then try
> > > > >
> > > > >
> > > > > --
> > > > > Jacob (MVP - Excel)
> > > > >
> > > > >
> > > > > "xp" wrote:
> > > > >
> > > > > > 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!