I have an Excel File open and have performed some functions on it. Now I want
to get a reference to this file and close it without saving changes by
feeding the file name to a function, but this doesn't work; can someone
please correct it for me?

Function FileCloseXLSNoSave(argFileName)
Set oXL = GetObject("", "Excel.Application")
Set oWB = oXL.Workbooks.Close argFileName, False
Set oWB = Nothing
Set oXL = Nothing
End Function

Thanks much in advance.

Re: Get reference and close Excel file without saving by Luuk

Luuk
Mon Jul 21 14:00:12 CDT 2008

XP schreef:
> I have an Excel File open and have performed some functions on it. Now I want
> to get a reference to this file and close it without saving changes by
> feeding the file name to a function, but this doesn't work; can someone
> please correct it for me?
>
> Function FileCloseXLSNoSave(argFileName)
> Set oXL = GetObject("", "Excel.Application")
> Set oWB = oXL.Workbooks.Close argFileName, False
> Set oWB = Nothing
> Set oXL = Nothing
> End Function
>
> Thanks much in advance.


Set oXL = GetObject("", "Excel.Application")
wscript.echo oXL.Workbooks.count
Set oXL = Nothing


returns "0" to me, even if i have a file open in Excel, so i think this
is the wrong way to solve your problem, but i'm not an expert in
vbscript ..... ;-)

--
Luuk

RE: Get reference and close Excel file without saving by XP

XP
Mon Jul 21 15:06:02 CDT 2008


After much experimentation, I solved it using my method.

Thanks.

"XP" wrote:

> I have an Excel File open and have performed some functions on it. Now I want
> to get a reference to this file and close it without saving changes by
> feeding the file name to a function, but this doesn't work; can someone
> please correct it for me?
>
> Function FileCloseXLSNoSave(argFileName)
> Set oXL = GetObject("", "Excel.Application")
> Set oWB = oXL.Workbooks.Close argFileName, False
> Set oWB = Nothing
> Set oXL = Nothing
> End Function
>
> Thanks much in advance.